diff --git a/contracts/asset-proxy/test/erc1155_proxy.ts b/contracts/asset-proxy/test/erc1155_proxy.ts index 8a7f852065..921dca9665 100644 --- a/contracts/asset-proxy/test/erc1155_proxy.ts +++ b/contracts/asset-proxy/test/erc1155_proxy.ts @@ -15,9 +15,10 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; +import { SafeMathRevertErrors } from '@0x/contracts-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { AssetProxyId, RevertReason } from '@0x/types'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as ethUtil from 'ethereumjs-util'; diff --git a/contracts/asset-proxy/test/erc20bridge_proxy.ts b/contracts/asset-proxy/test/erc20bridge_proxy.ts index 5df7181165..6e7388111a 100644 --- a/contracts/asset-proxy/test/erc20bridge_proxy.ts +++ b/contracts/asset-proxy/test/erc20bridge_proxy.ts @@ -9,8 +9,9 @@ import { Numberish, randomAddress, } from '@0x/contracts-test-utils'; +import { AuthorizableRevertErrors } from '@0x/contracts-utils'; import { AssetProxyId } from '@0x/types'; -import { AbiEncoder, AuthorizableRevertErrors, BigNumber, StringRevertError } from '@0x/utils'; +import { AbiEncoder, BigNumber, StringRevertError } from '@0x/utils'; import { DecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; diff --git a/contracts/coordinator/CHANGELOG.json b/contracts/coordinator/CHANGELOG.json index af648d5ff6..8468459169 100644 --- a/contracts/coordinator/CHANGELOG.json +++ b/contracts/coordinator/CHANGELOG.json @@ -5,6 +5,14 @@ { "note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils", "pr": 2330 + }, + { + "note": "Introduced new export CoordinatorRevertErrors", + "pr": 2321 + }, + { + "note": "Added dependency on @0x/contracts-utils", + "pr": 2321 } ] }, diff --git a/contracts/coordinator/package.json b/contracts/coordinator/package.json index 16436de2d5..b8513d35ea 100644 --- a/contracts/coordinator/package.json +++ b/contracts/coordinator/package.json @@ -81,6 +81,7 @@ }, "dependencies": { "@0x/base-contract": "^5.5.0-beta.1", + "@0x/contracts-utils": "^3.3.0-beta.1", "@0x/types": "^2.5.0-beta.1", "@0x/typescript-typings": "^4.4.0-beta.1", "@0x/utils": "^4.6.0-beta.1", diff --git a/contracts/coordinator/src/approval_factory.ts b/contracts/coordinator/src/approval_factory.ts index 97c2ae999a..701dc4a0a0 100644 --- a/contracts/coordinator/src/approval_factory.ts +++ b/contracts/coordinator/src/approval_factory.ts @@ -13,12 +13,16 @@ export class ApprovalFactory { this._verifyingContractAddress = verifyingContract; } - public newSignedApproval( + public async newSignedApprovalAsync( transaction: SignedZeroExTransaction, txOrigin: string, signatureType: SignatureType = SignatureType.EthSign, - ): SignedCoordinatorApproval { - const approvalHashBuff = hashUtils.getApprovalHashBuffer(transaction, this._verifyingContractAddress, txOrigin); + ): Promise { + const approvalHashBuff = await hashUtils.getApprovalHashBufferAsync( + transaction, + this._verifyingContractAddress, + txOrigin, + ); const signatureBuff = signingUtils.signMessage(approvalHashBuff, this._privateKey, signatureType); const signedApproval = { txOrigin, diff --git a/contracts/coordinator/src/hash_utils.ts b/contracts/coordinator/src/hash_utils.ts index 1781608e49..5b6a10e7f3 100644 --- a/contracts/coordinator/src/hash_utils.ts +++ b/contracts/coordinator/src/hash_utils.ts @@ -4,13 +4,25 @@ import { SignedZeroExTransaction } from '@0x/types'; import { signTypedDataUtils } from '@0x/utils'; export const hashUtils = { - getApprovalHashBuffer(transaction: SignedZeroExTransaction, verifyingContract: string, txOrigin: string): Buffer { - const typedData = eip712Utils.createCoordinatorApprovalTypedData(transaction, verifyingContract, txOrigin); + async getApprovalHashBufferAsync( + transaction: SignedZeroExTransaction, + verifyingContract: string, + txOrigin: string, + ): Promise { + const typedData = await eip712Utils.createCoordinatorApprovalTypedDataAsync( + transaction, + verifyingContract, + txOrigin, + ); const hashBuffer = signTypedDataUtils.generateTypedDataHash(typedData); return hashBuffer; }, - getApprovalHashHex(transaction: SignedZeroExTransaction, verifyingContract: string, txOrigin: string): string { - const hashHex = hexConcat(hashUtils.getApprovalHashBuffer(transaction, verifyingContract, txOrigin)); + async getApprovalHashHexAsync( + transaction: SignedZeroExTransaction, + verifyingContract: string, + txOrigin: string, + ): Promise { + const hashHex = hexConcat(await hashUtils.getApprovalHashBufferAsync(transaction, verifyingContract, txOrigin)); return hashHex; }, }; diff --git a/contracts/coordinator/src/index.ts b/contracts/coordinator/src/index.ts index fc96ee9ddc..afa6f1d0c6 100644 --- a/contracts/coordinator/src/index.ts +++ b/contracts/coordinator/src/index.ts @@ -1,4 +1,5 @@ export * from './artifacts'; export * from './wrappers'; +export import CoordinatorRevertErrors = require('./revert_errors'); export { ApprovalFactory } from './approval_factory'; export { SignedCoordinatorApproval } from './types'; diff --git a/packages/order-utils/src/coordinator_revert_errors.ts b/contracts/coordinator/src/revert_errors.ts similarity index 100% rename from packages/order-utils/src/coordinator_revert_errors.ts rename to contracts/coordinator/src/revert_errors.ts diff --git a/contracts/coordinator/test/libs.ts b/contracts/coordinator/test/libs.ts index 3b19d521b7..4d44d7d836 100644 --- a/contracts/coordinator/test/libs.ts +++ b/contracts/coordinator/test/libs.ts @@ -1,5 +1,4 @@ -import { blockchainTests, constants, expect, randomAddress } from '@0x/contracts-test-utils'; -import { transactionHashUtils } from '@0x/order-utils'; +import { blockchainTests, constants, expect, randomAddress, transactionHashUtils } from '@0x/contracts-test-utils'; import { BigNumber } from '@0x/utils'; import { hashUtils } from '../src/hash_utils'; @@ -45,7 +44,11 @@ blockchainTests.resets('Libs tests', env => { transactionHash: transactionHashUtils.getTransactionHashHex(signedTx), transactionSignature: signedTx.signature, }; - const expectedApprovalHash = hashUtils.getApprovalHashHex(signedTx, coordinatorContract.address, txOrigin); + const expectedApprovalHash = await hashUtils.getApprovalHashHexAsync( + signedTx, + coordinatorContract.address, + txOrigin, + ); const approvalHash = await coordinatorContract.getCoordinatorApprovalHash(approval).callAsync(); expect(expectedApprovalHash).to.eq(approvalHash); }); diff --git a/contracts/coordinator/test/mixins.ts b/contracts/coordinator/test/mixins.ts index 78fc05c27a..57f22a9a4d 100644 --- a/contracts/coordinator/test/mixins.ts +++ b/contracts/coordinator/test/mixins.ts @@ -8,10 +8,13 @@ import { hexSlice, randomAddress, TransactionFactory, + transactionHashUtils, } from '@0x/contracts-test-utils'; -import { CoordinatorRevertErrors, transactionHashUtils } from '@0x/order-utils'; +import { LibBytesRevertErrors } from '@0x/contracts-utils'; import { SignatureType, SignedOrder } from '@0x/types'; -import { BigNumber, LibBytesRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; + +import CoordinatorRevertErrors = require('../src/revert_errors'); import { ApprovalFactory } from '../src/approval_factory'; @@ -237,7 +240,7 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); + const approval = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); await mixins .assertValidCoordinatorApprovals(transaction, transactionSignerAddress, transaction.signature, [ approval.signature, @@ -252,7 +255,7 @@ blockchainTests.resets('Mixins tests', env => { const orders = [order]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); + const approval = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); await mixins .assertValidCoordinatorApprovals(transaction, transactionSignerAddress, transaction.signature, [ approval.signature, @@ -273,7 +276,7 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); + const approval = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); await mixins .assertValidCoordinatorApprovals(transaction, approvalSignerAddress1, transaction.signature, [ approval.signature, @@ -294,7 +297,7 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); + const approval = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); const signature = hexConcat( hexSlice(approval.signature, 0, 2), '0xFFFFFFFF', @@ -315,7 +318,7 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); + const approval = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); const tx = mixins .assertValidCoordinatorApprovals(transaction, transactionSignerAddress, transaction.signature, [ @@ -336,7 +339,7 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder, defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); + const approval = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); await mixins .assertValidCoordinatorApprovals(transaction, transactionSignerAddress, transaction.signature, [ approval.signature, @@ -350,7 +353,7 @@ blockchainTests.resets('Mixins tests', env => { })); const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); + const approval = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); await mixins .assertValidCoordinatorApprovals(transaction, transactionSignerAddress, transaction.signature, [ approval.signature, @@ -372,7 +375,7 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder, { ...defaultOrder, senderAddress: constants.NULL_ADDRESS }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); + const approval = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); await mixins .assertValidCoordinatorApprovals(transaction, transactionSignerAddress, transaction.signature, [ approval.signature, @@ -383,8 +386,8 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder, { ...defaultOrder, feeRecipientAddress: approvalSignerAddress2 }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval1 = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); - const approval2 = approvalFactory2.newSignedApproval(transaction, transactionSignerAddress); + const approval1 = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); + const approval2 = await approvalFactory2.newSignedApprovalAsync(transaction, transactionSignerAddress); await mixins .assertValidCoordinatorApprovals(transaction, transactionSignerAddress, transaction.signature, [ approval1.signature, @@ -404,7 +407,7 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder, { ...defaultOrder, feeRecipientAddress: approvalSignerAddress2 }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval2 = approvalFactory2.newSignedApproval(transaction, transactionSignerAddress); + const approval2 = await approvalFactory2.newSignedApprovalAsync(transaction, transactionSignerAddress); const tx = mixins .assertValidCoordinatorApprovals(transaction, transactionSignerAddress, transaction.signature, [ @@ -430,7 +433,7 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder, defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); + const approval = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); const signature = hexConcat( hexSlice(approval.signature, 0, 2), '0xFFFFFFFF', @@ -451,8 +454,8 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder, { ...defaultOrder, feeRecipientAddress: approvalSignerAddress2 }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval1 = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); - const approval2 = approvalFactory2.newSignedApproval(transaction, transactionSignerAddress); + const approval1 = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); + const approval2 = await approvalFactory2.newSignedApprovalAsync(transaction, transactionSignerAddress); const approvalSignature2 = hexConcat( hexSlice(approval2.signature, 0, 2), '0xFFFFFFFF', @@ -474,7 +477,7 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder, { ...defaultOrder, feeRecipientAddress: approvalSignerAddress2 }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval2 = approvalFactory2.newSignedApproval(transaction, transactionSignerAddress); + const approval2 = await approvalFactory2.newSignedApprovalAsync(transaction, transactionSignerAddress); const approvalSignature2 = hexConcat( hexSlice(approval2.signature, 0, 2), '0xFFFFFFFF', @@ -495,7 +498,7 @@ blockchainTests.resets('Mixins tests', env => { const orders = [defaultOrder, defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = await transactionFactory.newSignedTransactionAsync({ data }); - const approval1 = approvalFactory1.newSignedApproval(transaction, transactionSignerAddress); + const approval1 = await approvalFactory1.newSignedApprovalAsync(transaction, transactionSignerAddress); const tx = mixins .assertValidCoordinatorApprovals(transaction, transactionSignerAddress, transaction.signature, [ diff --git a/contracts/dev-utils/CHANGELOG.json b/contracts/dev-utils/CHANGELOG.json index 28422f6e3f..74d14f0574 100644 --- a/contracts/dev-utils/CHANGELOG.json +++ b/contracts/dev-utils/CHANGELOG.json @@ -5,6 +5,14 @@ { "note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils", "pr": 2330 + }, + { + "note": "Add new method getOrderHash() to DevUtils contract", + "pr": 2321 + }, + { + "note": "Add new method getTransactionHash() to DevUtils contract", + "pr": 2321 } ] }, diff --git a/contracts/dev-utils/compiler.json b/contracts/dev-utils/compiler.json index 220e81a33a..f5ff33c6b1 100644 --- a/contracts/dev-utils/compiler.json +++ b/contracts/dev-utils/compiler.json @@ -7,7 +7,7 @@ "evmVersion": "constantinople", "optimizer": { "enabled": true, - "runs": 10000, + "runs": 1666, "details": { "yul": true, "deduplicate": true, "cse": true, "constantOptimizer": true } }, "outputSelection": { diff --git a/contracts/dev-utils/contracts/src/DevUtils.sol b/contracts/dev-utils/contracts/src/DevUtils.sol index 44166d22b9..210da5c943 100644 --- a/contracts/dev-utils/contracts/src/DevUtils.sol +++ b/contracts/dev-utils/contracts/src/DevUtils.sol @@ -19,6 +19,11 @@ pragma solidity ^0.5.5; pragma experimental ABIEncoderV2; +import "@0x/contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomain.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol"; +import "@0x/contracts-utils/contracts/src/LibEIP712.sol"; +import "@0x/contracts-utils/contracts/src/LibBytes.sol"; import "./OrderValidationUtils.sol"; import "./OrderTransferSimulationUtils.sol"; import "./LibTransactionDecoder.sol"; @@ -29,6 +34,7 @@ import "./EthBalanceChecker.sol"; contract DevUtils is OrderValidationUtils, LibTransactionDecoder, + LibEIP712ExchangeDomain, EthBalanceChecker, OrderTransferSimulationUtils { @@ -36,5 +42,32 @@ contract DevUtils is public OrderValidationUtils(_exchange) OrderTransferSimulationUtils(_exchange) + LibEIP712ExchangeDomain(uint256(0), address(0)) // null args because because we only use constants {} + + function getOrderHash(LibOrder.Order memory order, uint256 chainId, address exchange) + public + pure + returns (bytes32 orderHash) + { + return LibOrder.getTypedDataHash( + order, + LibEIP712.hashEIP712Domain(_EIP712_EXCHANGE_DOMAIN_NAME, _EIP712_EXCHANGE_DOMAIN_VERSION, chainId, exchange) + ); + } + + function getTransactionHash( + LibZeroExTransaction.ZeroExTransaction memory transaction, + uint256 chainId, + address exchange + ) + public + pure + returns (bytes32 transactionHash) + { + return LibZeroExTransaction.getTypedDataHash( + transaction, + LibEIP712.hashEIP712Domain(_EIP712_EXCHANGE_DOMAIN_NAME, _EIP712_EXCHANGE_DOMAIN_VERSION, chainId, exchange) + ); + } } diff --git a/contracts/dev-utils/package.json b/contracts/dev-utils/package.json index da8e082cf3..d655ca8b58 100644 --- a/contracts/dev-utils/package.json +++ b/contracts/dev-utils/package.json @@ -8,7 +8,8 @@ "main": "lib/src/index.js", "scripts": { "build": "yarn pre_build && tsc -b", - "test": "echo !!! Run tests in @0x/contracts-tests instead !!!", + "test": "yarn assert_deployable && echo !!! Tests are run via @0x/contracts-tests !!!", + "assert_deployable": "node -e \"const bytecodeLen = (require('./generated-artifacts/DevUtils.json').compilerOutput.evm.bytecode.object.length-2)/2; assert(bytecodeLen<=0x6000,'DevUtils contract is too big to deploy, per EIP-170. '+bytecodeLen+'>'+0x6000)\"", "build:ci": "yarn build", "pre_build": "run-s compile quantify_bytecode contracts:gen generate_contract_wrappers contracts:copy", "compile": "sol-compiler", diff --git a/contracts/erc1155/test/erc1155_token.ts b/contracts/erc1155/test/erc1155_token.ts index 71d2821337..24e2797bdb 100644 --- a/contracts/erc1155/test/erc1155_token.ts +++ b/contracts/erc1155/test/erc1155_token.ts @@ -6,9 +6,10 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; +import { SafeMathRevertErrors } from '@0x/contracts-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { RevertReason } from '@0x/types'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; diff --git a/contracts/exchange-forwarder/CHANGELOG.json b/contracts/exchange-forwarder/CHANGELOG.json index ef22a71bd8..de5500643b 100644 --- a/contracts/exchange-forwarder/CHANGELOG.json +++ b/contracts/exchange-forwarder/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils", "pr": 2330 + }, + { + "note": "Introduced new export ForwarderRevertErrors", + "pr": 2321 } ] }, diff --git a/contracts/exchange-forwarder/src/index.ts b/contracts/exchange-forwarder/src/index.ts index d55f08ea2d..573031ae1b 100644 --- a/contracts/exchange-forwarder/src/index.ts +++ b/contracts/exchange-forwarder/src/index.ts @@ -1,2 +1,3 @@ export * from './artifacts'; export * from './wrappers'; +export import ForwarderRevertErrors = require('./revert_errors'); diff --git a/packages/order-utils/src/forwarder_revert_errors.ts b/contracts/exchange-forwarder/src/revert_errors.ts similarity index 100% rename from packages/order-utils/src/forwarder_revert_errors.ts rename to contracts/exchange-forwarder/src/revert_errors.ts diff --git a/contracts/exchange-libs/CHANGELOG.json b/contracts/exchange-libs/CHANGELOG.json index 40e35e91f8..07051cc835 100644 --- a/contracts/exchange-libs/CHANGELOG.json +++ b/contracts/exchange-libs/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils", "pr": 2330 + }, + { + "note": "Introduced new export LibMathRevertErrors", + "pr": 2321 } ] }, diff --git a/contracts/exchange-libs/src/index.ts b/contracts/exchange-libs/src/index.ts index 0233c608d1..44b3dd4d82 100644 --- a/contracts/exchange-libs/src/index.ts +++ b/contracts/exchange-libs/src/index.ts @@ -1,5 +1,6 @@ export * from './artifacts'; export * from './wrappers'; +export import LibMathRevertErrors = require('./lib_math_revert_errors'); import * as ReferenceFunctionsToExport from './reference_functions'; export import ReferenceFunctions = ReferenceFunctionsToExport; diff --git a/packages/order-utils/src/lib_math_revert_errors.ts b/contracts/exchange-libs/src/lib_math_revert_errors.ts similarity index 100% rename from packages/order-utils/src/lib_math_revert_errors.ts rename to contracts/exchange-libs/src/lib_math_revert_errors.ts diff --git a/contracts/exchange-libs/src/reference_functions.ts b/contracts/exchange-libs/src/reference_functions.ts index 6b77a3cea8..e3ebdf921d 100644 --- a/contracts/exchange-libs/src/reference_functions.ts +++ b/contracts/exchange-libs/src/reference_functions.ts @@ -1,8 +1,9 @@ import { ReferenceFunctions } from '@0x/contracts-utils'; -import { LibMathRevertErrors } from '@0x/order-utils'; import { FillResults, Order } from '@0x/types'; import { BigNumber } from '@0x/utils'; +import LibMathRevertErrors = require('./lib_math_revert_errors'); + const { safeAdd, safeSub, safeMul, safeDiv } = ReferenceFunctions; /** diff --git a/contracts/exchange-libs/test/lib_fill_results.ts b/contracts/exchange-libs/test/lib_fill_results.ts index 7e79a3a1d9..694d2e3e5e 100644 --- a/contracts/exchange-libs/test/lib_fill_results.ts +++ b/contracts/exchange-libs/test/lib_fill_results.ts @@ -7,12 +7,13 @@ import { testCombinatoriallyWithReferenceFunc, uint256Values, } from '@0x/contracts-test-utils'; -import { LibMathRevertErrors } from '@0x/order-utils'; +import { SafeMathRevertErrors } from '@0x/contracts-utils'; import { FillResults, MatchedFillResults, Order } from '@0x/types'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import * as _ from 'lodash'; +import LibMathRevertErrors = require('../src/lib_math_revert_errors'); import { addFillResults, calculateFillResults, getPartialAmountFloor } from '../src/reference_functions'; import { artifacts } from './artifacts'; diff --git a/contracts/exchange-libs/test/lib_math.ts b/contracts/exchange-libs/test/lib_math.ts index 3834c3b6b2..30f0441370 100644 --- a/contracts/exchange-libs/test/lib_math.ts +++ b/contracts/exchange-libs/test/lib_math.ts @@ -6,9 +6,10 @@ import { testCombinatoriallyWithReferenceFunc, uint256Values, } from '@0x/contracts-test-utils'; -import { LibMathRevertErrors } from '@0x/order-utils'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { SafeMathRevertErrors } from '@0x/contracts-utils'; +import { BigNumber } from '@0x/utils'; +import LibMathRevertErrors = require('../src/lib_math_revert_errors'); import { getPartialAmountCeil, getPartialAmountFloor, diff --git a/contracts/exchange-libs/test/lib_order.ts b/contracts/exchange-libs/test/lib_order.ts index 65cdc289dd..730e2db1fa 100644 --- a/contracts/exchange-libs/test/lib_order.ts +++ b/contracts/exchange-libs/test/lib_order.ts @@ -1,5 +1,5 @@ -import { blockchainTests, constants, describe, expect, hexRandom } from '@0x/contracts-test-utils'; -import { eip712Utils, orderHashUtils } from '@0x/order-utils'; +import { blockchainTests, constants, describe, expect, hexRandom, orderHashUtils } from '@0x/contracts-test-utils'; +import { eip712Utils } from '@0x/order-utils'; import { Order } from '@0x/types'; import { BigNumber, signTypedDataUtils } from '@0x/utils'; import * as ethUtil from 'ethereumjs-util'; diff --git a/contracts/exchange-libs/test/lib_zero_ex_transaction.ts b/contracts/exchange-libs/test/lib_zero_ex_transaction.ts index 828497a629..8462c406cb 100644 --- a/contracts/exchange-libs/test/lib_zero_ex_transaction.ts +++ b/contracts/exchange-libs/test/lib_zero_ex_transaction.ts @@ -1,5 +1,12 @@ -import { blockchainTests, constants, describe, expect, hexRandom } from '@0x/contracts-test-utils'; -import { eip712Utils, transactionHashUtils } from '@0x/order-utils'; +import { + blockchainTests, + constants, + describe, + expect, + hexRandom, + transactionHashUtils, +} from '@0x/contracts-test-utils'; +import { eip712Utils } from '@0x/order-utils'; import { ZeroExTransaction } from '@0x/types'; import { BigNumber, signTypedDataUtils } from '@0x/utils'; import * as ethUtil from 'ethereumjs-util'; diff --git a/contracts/exchange-libs/test/reference_functions.ts b/contracts/exchange-libs/test/reference_functions.ts index cd205126cd..797cace298 100644 --- a/contracts/exchange-libs/test/reference_functions.ts +++ b/contracts/exchange-libs/test/reference_functions.ts @@ -1,8 +1,9 @@ import { constants, describe, expect } from '@0x/contracts-test-utils'; -import { LibMathRevertErrors } from '@0x/order-utils'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { SafeMathRevertErrors } from '@0x/contracts-utils'; +import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; +import LibMathRevertErrors = require('../src/lib_math_revert_errors'); import { addFillResults, getPartialAmountCeil, diff --git a/contracts/exchange/CHANGELOG.json b/contracts/exchange/CHANGELOG.json index 6fa9b1c63a..87ab529067 100644 --- a/contracts/exchange/CHANGELOG.json +++ b/contracts/exchange/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils", "pr": 2330 + }, + { + "note": "Introduced new export ExchangeRevertErrors", + "pr": 2321 } ] }, diff --git a/contracts/exchange/src/exchange_data_encoder.ts b/contracts/exchange/src/exchange_data_encoder.ts index 06830bf8fe..c9bf297bab 100644 --- a/contracts/exchange/src/exchange_data_encoder.ts +++ b/contracts/exchange/src/exchange_data_encoder.ts @@ -1,5 +1,4 @@ -import { constants, ExchangeFunctionName, provider } from '@0x/contracts-test-utils'; -import { orderHashUtils } from '@0x/order-utils'; +import { constants, ExchangeFunctionName, orderHashUtils, provider } from '@0x/contracts-test-utils'; import { SignedOrder } from '@0x/types'; import { IExchangeContract } from './wrappers'; diff --git a/contracts/exchange/src/index.ts b/contracts/exchange/src/index.ts index db2a3f1ec4..7d80a4e498 100644 --- a/contracts/exchange/src/index.ts +++ b/contracts/exchange/src/index.ts @@ -1,5 +1,6 @@ export * from './artifacts'; export * from './wrappers'; +export import ExchangeRevertErrors = require('./revert_errors'); export { BlockchainBalanceStore } from './balance_stores/blockchain_balance_store'; export { LocalBalanceStore } from './balance_stores/local_balance_store'; export { exchangeDataEncoder } from './exchange_data_encoder'; diff --git a/packages/order-utils/src/exchange_revert_errors.ts b/contracts/exchange/src/revert_errors.ts similarity index 100% rename from packages/order-utils/src/exchange_revert_errors.ts rename to contracts/exchange/src/revert_errors.ts diff --git a/contracts/exchange/test/assertion_wrappers/fill_order_wrapper.ts b/contracts/exchange/test/assertion_wrappers/fill_order_wrapper.ts index a5dc4cd6ad..c93c3037bb 100644 --- a/contracts/exchange/test/assertion_wrappers/fill_order_wrapper.ts +++ b/contracts/exchange/test/assertion_wrappers/fill_order_wrapper.ts @@ -5,10 +5,10 @@ import { expect, FillEventArgs, filterLogsToArguments, + orderHashUtils, OrderStatus, orderUtils, } from '@0x/contracts-test-utils'; -import { orderHashUtils } from '@0x/order-utils'; import { FillResults, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; diff --git a/contracts/exchange/test/core.ts b/contracts/exchange/test/core.ts index 743d415fcf..e07332edf1 100644 --- a/contracts/exchange/test/core.ts +++ b/contracts/exchange/test/core.ts @@ -18,6 +18,7 @@ import { DummyNoReturnERC20TokenContract, } from '@0x/contracts-erc20'; import { DummyERC721TokenContract } from '@0x/contracts-erc721'; +import { LibMathRevertErrors } from '@0x/contracts-exchange-libs'; import { blockchainTests, constants, @@ -28,18 +29,20 @@ import { hexConcat, increaseTimeAndMineBlockAsync, OrderFactory, + orderHashUtils, OrderStatus, provider, txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { ExchangeRevertErrors, LibMathRevertErrors, orderHashUtils } from '@0x/order-utils'; import { RevertReason, SignatureType, SignedOrder } from '@0x/types'; import { BigNumber, providerUtils, StringRevertError } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; +import ExchangeRevertErrors = require('../src/revert_errors'); + import { ValidatorWalletAction } from './utils/constants'; import { ExchangeWrapper } from './utils/exchange_wrapper'; diff --git a/contracts/exchange/test/dispatcher.ts b/contracts/exchange/test/dispatcher.ts index 51fd67329a..9bbcb4fed1 100644 --- a/contracts/exchange/test/dispatcher.ts +++ b/contracts/exchange/test/dispatcher.ts @@ -16,14 +16,16 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; +import { OwnableRevertErrors } from '@0x/contracts-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; -import { ExchangeRevertErrors } from '@0x/order-utils'; import { AssetProxyId, RevertReason } from '@0x/types'; -import { BigNumber, OwnableRevertErrors, StringRevertError } from '@0x/utils'; +import { BigNumber, StringRevertError } from '@0x/utils'; import * as chai from 'chai'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; +import ExchangeRevertErrors = require('../src/revert_errors'); + import { artifacts } from './artifacts'; import { TestAssetProxyDispatcherAssetProxyRegisteredEventArgs, TestAssetProxyDispatcherContract } from './wrappers'; diff --git a/contracts/exchange/test/internal.ts b/contracts/exchange/test/internal.ts index e9aa0c9bfd..6968bc05d4 100644 --- a/contracts/exchange/test/internal.ts +++ b/contracts/exchange/test/internal.ts @@ -1,12 +1,14 @@ import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs'; -import { blockchainTests, constants, expect, hexRandom } from '@0x/contracts-test-utils'; -import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils'; +import { blockchainTests, constants, expect, hexRandom, orderHashUtils } from '@0x/contracts-test-utils'; +import { SafeMathRevertErrors } from '@0x/contracts-utils'; import { Order } from '@0x/types'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; +import ExchangeRevertErrors = require('../src/revert_errors'); + import { artifacts } from './artifacts'; import { TestExchangeInternalsContract, diff --git a/contracts/exchange/test/isolated_fill_order.ts b/contracts/exchange/test/isolated_fill_order.ts index ef889fd781..057d3d090f 100644 --- a/contracts/exchange/test/isolated_fill_order.ts +++ b/contracts/exchange/test/isolated_fill_order.ts @@ -1,10 +1,12 @@ -import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs'; +import { LibMathRevertErrors, ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs'; import { blockchainTests, constants, expect, hexRandom } from '@0x/contracts-test-utils'; -import { ExchangeRevertErrors, LibMathRevertErrors } from '@0x/order-utils'; +import { SafeMathRevertErrors } from '@0x/contracts-utils'; import { FillResults, OrderInfo, OrderStatus, SignatureType } from '@0x/types'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; +import ExchangeRevertErrors = require('../src/revert_errors'); + import { AssetBalances, createBadAssetData, diff --git a/contracts/exchange/test/lib_exchange_rich_error_decoder.ts b/contracts/exchange/test/lib_exchange_rich_error_decoder.ts index 7d7185b956..61c9ad1f72 100644 --- a/contracts/exchange/test/lib_exchange_rich_error_decoder.ts +++ b/contracts/exchange/test/lib_exchange_rich_error_decoder.ts @@ -7,10 +7,12 @@ import { orderUtils, randomAddress, } from '@0x/contracts-test-utils'; -import { ExchangeRevertErrors, generatePseudoRandomSalt } from '@0x/order-utils'; +import { generatePseudoRandomSalt } from '@0x/order-utils'; import { BigNumber, RevertError } from '@0x/utils'; import * as _ from 'lodash'; +import ExchangeRevertErrors = require('../src/revert_errors'); + import { artifacts } from './artifacts'; import { TestLibExchangeRichErrorDecoderContract } from './wrappers'; diff --git a/contracts/exchange/test/match_orders.ts b/contracts/exchange/test/match_orders.ts index 820a6acbdd..958004077d 100644 --- a/contracts/exchange/test/match_orders.ts +++ b/contracts/exchange/test/match_orders.ts @@ -17,19 +17,21 @@ import { chaiSetup, constants, OrderFactory, + orderHashUtils, orderUtils, provider, txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; -import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils'; import { OrderStatus, SignedOrder } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import * as chai from 'chai'; import * as _ from 'lodash'; +import ExchangeRevertErrors = require('../src/revert_errors'); + import { ExchangeWrapper } from './utils/exchange_wrapper'; import { artifacts } from './artifacts'; diff --git a/contracts/exchange/test/protocol_fees_manager.ts b/contracts/exchange/test/protocol_fees_manager.ts index 8d56dea1c1..b0ba3ac508 100644 --- a/contracts/exchange/test/protocol_fees_manager.ts +++ b/contracts/exchange/test/protocol_fees_manager.ts @@ -1,5 +1,6 @@ import { blockchainTests, constants, expect } from '@0x/contracts-test-utils'; -import { BigNumber, OwnableRevertErrors } from '@0x/utils'; +import { OwnableRevertErrors } from '@0x/contracts-utils'; +import { BigNumber } from '@0x/utils'; import { LogWithDecodedArgs } from 'ethereum-types'; import { artifacts } from './artifacts'; diff --git a/contracts/exchange/test/reference_functions.ts b/contracts/exchange/test/reference_functions.ts index fc15440ea5..65d3378a79 100644 --- a/contracts/exchange/test/reference_functions.ts +++ b/contracts/exchange/test/reference_functions.ts @@ -1,8 +1,8 @@ -import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs'; +import { LibMathRevertErrors, ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs'; import { constants, describe, expect } from '@0x/contracts-test-utils'; -import { LibMathRevertErrors } from '@0x/order-utils'; +import { SafeMathRevertErrors } from '@0x/contracts-utils'; import { Order } from '@0x/types'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; describe('Reference functions', () => { diff --git a/contracts/exchange/test/signature_validator.ts b/contracts/exchange/test/signature_validator.ts index d2fbf277ff..2de6fa2642 100644 --- a/contracts/exchange/test/signature_validator.ts +++ b/contracts/exchange/test/signature_validator.ts @@ -7,16 +7,19 @@ import { hexRandom, LogDecoder, OrderFactory, + orderHashUtils, orderUtils, randomAddress, TransactionFactory, + transactionHashUtils, } from '@0x/contracts-test-utils'; -import { ExchangeRevertErrors, orderHashUtils, transactionHashUtils } from '@0x/order-utils'; import { SignatureType, SignedOrder, SignedZeroExTransaction } from '@0x/types'; import { BigNumber, StringRevertError } from '@0x/utils'; import { LogWithDecodedArgs } from 'ethereum-types'; import ethUtil = require('ethereumjs-util'); +import ExchangeRevertErrors = require('../src/revert_errors'); + import { artifacts } from './artifacts'; import { IEIP1271DataContract, diff --git a/contracts/exchange/test/transactions.ts b/contracts/exchange/test/transactions.ts index 475a15d4ff..13d632ab4c 100644 --- a/contracts/exchange/test/transactions.ts +++ b/contracts/exchange/test/transactions.ts @@ -10,9 +10,10 @@ import { expect, getLatestBlockTimestampAsync, OrderFactory, + orderHashUtils, TransactionFactory, + transactionHashUtils, } from '@0x/contracts-test-utils'; -import { ExchangeRevertErrors, orderHashUtils, transactionHashUtils } from '@0x/order-utils'; import { FillResults, OrderStatus } from '@0x/types'; import { AbiEncoder, BigNumber } from '@0x/utils'; import { LogWithDecodedArgs, MethodAbi } from 'ethereum-types'; @@ -20,6 +21,7 @@ import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; import { exchangeDataEncoder } from '../src/exchange_data_encoder'; +import ExchangeRevertErrors = require('../src/revert_errors'); import { artifacts as localArtifacts } from './artifacts'; import { ExchangeWrapper } from './utils/exchange_wrapper'; diff --git a/contracts/exchange/test/transactions_unit_tests.ts b/contracts/exchange/test/transactions_unit_tests.ts index 37ffd6be33..87f1925256 100644 --- a/contracts/exchange/test/transactions_unit_tests.ts +++ b/contracts/exchange/test/transactions_unit_tests.ts @@ -1,10 +1,18 @@ -import { blockchainTests, constants, describe, expect, hexRandom } from '@0x/contracts-test-utils'; -import { ExchangeRevertErrors, transactionHashUtils } from '@0x/order-utils'; +import { + blockchainTests, + constants, + describe, + expect, + hexRandom, + transactionHashUtils, +} from '@0x/contracts-test-utils'; import { EIP712DomainWithDefaultSchema, ZeroExTransaction } from '@0x/types'; import { BigNumber, StringRevertError } from '@0x/utils'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; +import ExchangeRevertErrors = require('../src/revert_errors'); + import { artifacts } from './artifacts'; import { TestTransactionsContract, TestTransactionsTransactionExecutionEventArgs } from './wrappers'; diff --git a/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts b/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts index 53382e7eee..9a08ae78fb 100644 --- a/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts +++ b/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts @@ -6,8 +6,7 @@ import { MultiAssetProxyContract, } from '@0x/contracts-asset-proxy'; import { DevUtilsContract } from '@0x/contracts-dev-utils'; -import { constants, expect, LogDecoder, orderUtils, signingUtils } from '@0x/contracts-test-utils'; -import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils'; +import { constants, expect, LogDecoder, orderHashUtils, orderUtils, signingUtils } from '@0x/contracts-test-utils'; import { FillResults, Order, SignatureType, SignedOrder } from '@0x/types'; import { BigNumber, errorUtils, providerUtils, RevertError, StringRevertError } from '@0x/utils'; import { SupportedProvider, Web3Wrapper } from '@0x/web3-wrapper'; @@ -15,6 +14,8 @@ import { LogWithDecodedArgs, TxData } from 'ethereum-types'; import * as _ from 'lodash'; import 'make-promises-safe'; +import ExchangeRevertErrors = require('../../src/revert_errors'); + import { artifacts } from '../artifacts'; import { ExchangeContract, ExchangeFillEventArgs } from '../wrappers'; diff --git a/contracts/exchange/test/utils/isolated_exchange_wrapper.ts b/contracts/exchange/test/utils/isolated_exchange_wrapper.ts index 0085bea334..c89fc5af6a 100644 --- a/contracts/exchange/test/utils/isolated_exchange_wrapper.ts +++ b/contracts/exchange/test/utils/isolated_exchange_wrapper.ts @@ -1,5 +1,9 @@ -import { constants, filterLogsToArguments, txDefaults as testTxDefaults } from '@0x/contracts-test-utils'; -import { orderHashUtils } from '@0x/order-utils'; +import { + constants, + filterLogsToArguments, + orderHashUtils, + txDefaults as testTxDefaults, +} from '@0x/contracts-test-utils'; import { FillResults, Order, OrderInfo, SignatureType } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { TxData, Web3Wrapper } from '@0x/web3-wrapper'; diff --git a/contracts/exchange/test/utils/match_order_tester.ts b/contracts/exchange/test/utils/match_order_tester.ts index e8ec9a42b0..8c2f1a1556 100644 --- a/contracts/exchange/test/utils/match_order_tester.ts +++ b/contracts/exchange/test/utils/match_order_tester.ts @@ -1,7 +1,6 @@ import { ERC1155ProxyWrapper, ERC20Wrapper, ERC721Wrapper } from '@0x/contracts-asset-proxy'; import { DevUtilsContract } from '@0x/contracts-dev-utils'; -import { constants, ERC1155HoldingsByOwner, expect, OrderStatus } from '@0x/contracts-test-utils'; -import { orderHashUtils } from '@0x/order-utils'; +import { constants, ERC1155HoldingsByOwner, expect, orderHashUtils, OrderStatus } from '@0x/contracts-test-utils'; import { AssetProxyId, BatchMatchedFillResults, FillResults, MatchedFillResults, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; diff --git a/contracts/exchange/test/wrapper_unit_tests.ts b/contracts/exchange/test/wrapper_unit_tests.ts index 8476baa048..bcd9b6e06f 100644 --- a/contracts/exchange/test/wrapper_unit_tests.ts +++ b/contracts/exchange/test/wrapper_unit_tests.ts @@ -1,14 +1,15 @@ import { ContractTxFunctionObj } from '@0x/base-contract'; import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs'; -import { blockchainTests, constants, describe, expect, hexRandom } from '@0x/contracts-test-utils'; -import { ReferenceFunctions as UtilReferenceFunctions } from '@0x/contracts-utils'; -import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils'; +import { blockchainTests, constants, describe, expect, hexRandom, orderHashUtils } from '@0x/contracts-test-utils'; +import { ReferenceFunctions as UtilReferenceFunctions, SafeMathRevertErrors } from '@0x/contracts-utils'; import { FillResults, Order } from '@0x/types'; -import { AnyRevertError, BigNumber, SafeMathRevertErrors, StringRevertError } from '@0x/utils'; +import { AnyRevertError, BigNumber, StringRevertError } from '@0x/utils'; import { LogEntry, LogWithDecodedArgs } from 'ethereum-types'; import * as ethjs from 'ethereumjs-util'; import * as _ from 'lodash'; +import ExchangeRevertErrors = require('../src/revert_errors'); + import { artifacts } from './artifacts'; import { TestWrapperFunctionsCancelOrderCalledEventArgs as CancelOrderCalledEventArgs, diff --git a/contracts/extensions/test/balance_threshold_filter.ts b/contracts/extensions/test/balance_threshold_filter.ts index 033c2d732d..622ad5f5e9 100644 --- a/contracts/extensions/test/balance_threshold_filter.ts +++ b/contracts/extensions/test/balance_threshold_filter.ts @@ -1,7 +1,6 @@ import { DevUtilsContract } from '@0x/contracts-dev-utils'; -import { ExchangeContract } from '@0x/contracts-exchange'; +import { ExchangeRevertErrors } from '@0x/contracts-exchange'; import { BlockchainLifecycle } from '@0x/dev-utils'; -import { ExchangeRevertErrors } from '@0x/order-utils'; import { Order, RevertReason, SignedOrder } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; diff --git a/contracts/extensions/test/order_matcher.ts b/contracts/extensions/test/order_matcher.ts index 005b367110..33f0b32745 100644 --- a/contracts/extensions/test/order_matcher.ts +++ b/contracts/extensions/test/order_matcher.ts @@ -7,7 +7,7 @@ import { import { DevUtilsContract } from '@0x/contracts-dev-utils'; import { DummyERC20TokenContract } from '@0x/contracts-erc20'; import { artifacts as erc721Artifacts, DummyERC721TokenContract } from '@0x/contracts-erc721'; -import { ExchangeContract } from '@0x/contracts-exchange'; +import { ExchangeContract, ExchangeRevertErrors } from '@0x/contracts-exchange'; import { chaiSetup, constants, @@ -22,7 +22,6 @@ import { web3Wrapper, } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; -import { ExchangeRevertErrors } from '@0x/order-utils'; import { RevertReason } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; diff --git a/contracts/integrations/test/actors/fee_recipient.ts b/contracts/integrations/test/actors/fee_recipient.ts index 94d813c06a..4cdace00f3 100644 --- a/contracts/integrations/test/actors/fee_recipient.ts +++ b/contracts/integrations/test/actors/fee_recipient.ts @@ -10,11 +10,11 @@ interface FeeRecipientConfig extends ActorConfig { export interface FeeRecipientInterface { approvalFactory?: ApprovalFactory; - signCoordinatorApproval: ( + signCoordinatorApprovalAsync: ( transaction: SignedZeroExTransaction, txOrigin: string, signatureType?: SignatureType, - ) => SignedCoordinatorApproval; + ) => Promise; } /** @@ -45,15 +45,15 @@ export function FeeRecipientMixin(Base: TBase): TBase /** * Signs an coordinator transaction. */ - public signCoordinatorApproval( + public async signCoordinatorApprovalAsync( transaction: SignedZeroExTransaction, txOrigin: string, signatureType: SignatureType = SignatureType.EthSign, - ): SignedCoordinatorApproval { + ): Promise { if (this.approvalFactory === undefined) { throw new Error('No verifying contract provided in FeeRecipient constructor'); } - return this.approvalFactory.newSignedApproval(transaction, txOrigin, signatureType); + return this.approvalFactory.newSignedApprovalAsync(transaction, txOrigin, signatureType); } }; } diff --git a/contracts/integrations/test/coordinator/coordinator_test.ts b/contracts/integrations/test/coordinator/coordinator_test.ts index 0a863591af..711c77b22c 100644 --- a/contracts/integrations/test/coordinator/coordinator_test.ts +++ b/contracts/integrations/test/coordinator/coordinator_test.ts @@ -1,4 +1,4 @@ -import { CoordinatorContract, SignedCoordinatorApproval } from '@0x/contracts-coordinator'; +import { CoordinatorContract, CoordinatorRevertErrors, SignedCoordinatorApproval } from '@0x/contracts-coordinator'; import { DevUtilsContract } from '@0x/contracts-dev-utils'; import { BlockchainBalanceStore, @@ -16,10 +16,11 @@ import { expect, hexConcat, hexSlice, + orderHashUtils, provider, + transactionHashUtils, verifyEvents, } from '@0x/contracts-test-utils'; -import { CoordinatorRevertErrors, orderHashUtils, transactionHashUtils } from '@0x/order-utils'; import { SignedOrder, SignedZeroExTransaction } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; @@ -181,7 +182,7 @@ blockchainTests.resets('Coordinator integration tests', env => { data, gasPrice: DeploymentManager.gasPrice, }); - approval = feeRecipient.signCoordinatorApproval(transaction, taker.address); + approval = await feeRecipient.signCoordinatorApprovalAsync(transaction, taker.address); }); it(`${fnName} should fill the order with a signed approval`, async () => { @@ -299,7 +300,7 @@ blockchainTests.resets('Coordinator integration tests', env => { data, gasPrice: DeploymentManager.gasPrice, }); - approval = feeRecipient.signCoordinatorApproval(transaction, taker.address); + approval = await feeRecipient.signCoordinatorApprovalAsync(transaction, taker.address); }); it(`${fnName} should fill the orders with a signed approval`, async () => { diff --git a/contracts/integrations/test/forwarder/forwarder_test.ts b/contracts/integrations/test/forwarder/forwarder_test.ts index 9f88478dad..6067d3eec9 100644 --- a/contracts/integrations/test/forwarder/forwarder_test.ts +++ b/contracts/integrations/test/forwarder/forwarder_test.ts @@ -7,7 +7,7 @@ import { ExchangeContract, LocalBalanceStore, } from '@0x/contracts-exchange'; -import { artifacts, ForwarderContract } from '@0x/contracts-exchange-forwarder'; +import { artifacts, ForwarderContract, ForwarderRevertErrors } from '@0x/contracts-exchange-forwarder'; import { blockchainTests, constants, @@ -17,7 +17,6 @@ import { provider, toBaseUnitAmount, } from '@0x/contracts-test-utils'; -import { ForwarderRevertErrors } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import { Actor, actorAddressesByName, FeeRecipient, Maker } from '../actors'; diff --git a/contracts/integrations/test/internal-integration-tests/exchange_wrapper_test.ts b/contracts/integrations/test/internal-integration-tests/exchange_wrapper_test.ts index ffedd80f11..9d28130067 100644 --- a/contracts/integrations/test/internal-integration-tests/exchange_wrapper_test.ts +++ b/contracts/integrations/test/internal-integration-tests/exchange_wrapper_test.ts @@ -2,6 +2,7 @@ import { DevUtilsContract } from '@0x/contracts-dev-utils'; import { ERC20TokenEvents, ERC20TokenTransferEventArgs } from '@0x/contracts-erc20'; import { BlockchainBalanceStore, + ExchangeRevertErrors, IExchangeEvents, IExchangeFillEventArgs, LocalBalanceStore, @@ -14,11 +15,11 @@ import { expect, getLatestBlockTimestampAsync, Numberish, + orderHashUtils, provider, toBaseUnitAmount, verifyEvents, } from '@0x/contracts-test-utils'; -import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils'; import { FillResults, OrderStatus, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; diff --git a/contracts/integrations/test/internal-integration-tests/fillorder_test.ts b/contracts/integrations/test/internal-integration-tests/fillorder_test.ts index 0240c026b6..b8631ee80d 100644 --- a/contracts/integrations/test/internal-integration-tests/fillorder_test.ts +++ b/contracts/integrations/test/internal-integration-tests/fillorder_test.ts @@ -15,8 +15,15 @@ import { IStakingEventsRewardsPaidEventArgs, IStakingEventsStakingPoolEarnedRewardsInEpochEventArgs, } from '@0x/contracts-staking'; -import { blockchainTests, constants, expect, provider, toBaseUnitAmount, verifyEvents } from '@0x/contracts-test-utils'; -import { orderHashUtils } from '@0x/order-utils'; +import { + blockchainTests, + constants, + expect, + orderHashUtils, + provider, + toBaseUnitAmount, + verifyEvents, +} from '@0x/contracts-test-utils'; import { SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; diff --git a/contracts/multisig/test/zero_ex_governor.ts b/contracts/multisig/test/zero_ex_governor.ts index e963e8a8a5..101ea49f20 100644 --- a/contracts/multisig/test/zero_ex_governor.ts +++ b/contracts/multisig/test/zero_ex_governor.ts @@ -1,6 +1,7 @@ import { blockchainTests, constants, expect, getLatestBlockTimestampAsync, hexRandom } from '@0x/contracts-test-utils'; +import { LibBytesRevertErrors } from '@0x/contracts-utils'; import { RevertReason } from '@0x/types'; -import { BigNumber, LibBytesRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import { LogEntry, LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; diff --git a/contracts/staking/CHANGELOG.json b/contracts/staking/CHANGELOG.json index 1c20be9014..1d1532aa0a 100644 --- a/contracts/staking/CHANGELOG.json +++ b/contracts/staking/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils", "pr": 2330 + }, + { + "note": "Introduce new exports FixedMathRevertErrors and StakingRevertErrors", + "pr": 2321 } ] }, diff --git a/packages/utils/src/fixed_math_revert_errors.ts b/contracts/staking/src/fixed_math_revert_errors.ts similarity index 92% rename from packages/utils/src/fixed_math_revert_errors.ts rename to contracts/staking/src/fixed_math_revert_errors.ts index 5fb1f3ffc4..e0206d0be4 100644 --- a/packages/utils/src/fixed_math_revert_errors.ts +++ b/contracts/staking/src/fixed_math_revert_errors.ts @@ -1,5 +1,4 @@ -import { BigNumber } from './configured_bignumber'; -import { RevertError } from './revert_error'; +import { BigNumber, RevertError } from '@0x/utils'; // tslint:disable:max-classes-per-file diff --git a/contracts/staking/src/index.ts b/contracts/staking/src/index.ts index c1bac21842..50939c7de4 100644 --- a/contracts/staking/src/index.ts +++ b/contracts/staking/src/index.ts @@ -1,5 +1,7 @@ export * from './wrappers'; export * from './artifacts'; +export import FixedMathRevertErrors = require('./fixed_math_revert_errors'); +export import StakingRevertErrors = require('./staking_revert_errors'); export { constants } from './constants'; export { GlobalStakeByStatus, diff --git a/packages/order-utils/src/staking_revert_errors.ts b/contracts/staking/src/staking_revert_errors.ts similarity index 100% rename from packages/order-utils/src/staking_revert_errors.ts rename to contracts/staking/src/staking_revert_errors.ts diff --git a/contracts/staking/test/migration_test.ts b/contracts/staking/test/migration_test.ts index c6ddc00401..aebb814abe 100644 --- a/contracts/staking/test/migration_test.ts +++ b/contracts/staking/test/migration_test.ts @@ -1,8 +1,9 @@ import { blockchainTests, constants, expect, filterLogsToArguments } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; -import { AuthorizableRevertErrors, BigNumber, StringRevertError } from '@0x/utils'; +import { AuthorizableRevertErrors } from '@0x/contracts-utils'; +import { BigNumber, StringRevertError } from '@0x/utils'; import { constants as stakingConstants } from '../src/constants'; +import StakingRevertErrors = require('../src/staking_revert_errors'); import { artifacts } from './artifacts'; import { diff --git a/contracts/staking/test/pools_test.ts b/contracts/staking/test/pools_test.ts index d58f1f61dc..142a71394f 100644 --- a/contracts/staking/test/pools_test.ts +++ b/contracts/staking/test/pools_test.ts @@ -1,9 +1,9 @@ import { ERC20Wrapper } from '@0x/contracts-asset-proxy'; import { blockchainTests, constants, expect } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; import * as _ from 'lodash'; import { constants as stakingConstants } from '../src/constants'; +import StakingRevertErrors = require('../src/staking_revert_errors'); import { MakerActor } from './actors/maker_actor'; import { PoolOperatorActor } from './actors/pool_operator_actor'; diff --git a/contracts/staking/test/rewards_test.ts b/contracts/staking/test/rewards_test.ts index f83f3ef37f..098aa92a27 100644 --- a/contracts/staking/test/rewards_test.ts +++ b/contracts/staking/test/rewards_test.ts @@ -1,9 +1,9 @@ import { ERC20Wrapper } from '@0x/contracts-asset-proxy'; import { blockchainTests, constants, describe, expect, shortZip } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; +import StakingRevertErrors = require('../src/staking_revert_errors'); import { DelegatorsByPoolId, OperatorByPoolId, StakeInfo, StakeStatus } from '../src/types'; import { FinalizerActor } from './actors/finalizer_actor'; diff --git a/contracts/staking/test/stake_test.ts b/contracts/staking/test/stake_test.ts index cb5ac96b77..a530ad28a4 100644 --- a/contracts/staking/test/stake_test.ts +++ b/contracts/staking/test/stake_test.ts @@ -1,9 +1,9 @@ import { ERC20Wrapper } from '@0x/contracts-asset-proxy'; import { blockchainTests, describe } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; +import StakingRevertErrors = require('../src/staking_revert_errors'); import { StakeInfo, StakeStatus } from '../src/types'; import { StakerActor } from './actors/staker_actor'; diff --git a/contracts/staking/test/unit_tests/exchange_test.ts b/contracts/staking/test/unit_tests/exchange_test.ts index fba0d7b2d8..af3302f1c2 100644 --- a/contracts/staking/test/unit_tests/exchange_test.ts +++ b/contracts/staking/test/unit_tests/exchange_test.ts @@ -1,8 +1,9 @@ import { blockchainTests, expect } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; -import { AuthorizableRevertErrors } from '@0x/utils'; +import { AuthorizableRevertErrors } from '@0x/contracts-utils'; import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; +import StakingRevertErrors = require('../../src/staking_revert_errors'); + import { artifacts } from '../artifacts'; import { TestExchangeManagerContract, diff --git a/contracts/staking/test/unit_tests/finalizer_test.ts b/contracts/staking/test/unit_tests/finalizer_test.ts index 571b46502a..bf3f581b28 100644 --- a/contracts/staking/test/unit_tests/finalizer_test.ts +++ b/contracts/staking/test/unit_tests/finalizer_test.ts @@ -7,12 +7,13 @@ import { Numberish, shortZip, } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import { LogEntry } from 'ethereum-types'; import * as _ from 'lodash'; import { constants as stakingConstants } from '../../src/constants'; +import StakingRevertErrors = require('../../src/staking_revert_errors'); + import { artifacts } from '../artifacts'; import { assertIntegerRoughlyEquals, getRandomInteger, toBaseUnitAmount } from '../utils/number_utils'; diff --git a/contracts/staking/test/unit_tests/lib_fixed_math_test.ts b/contracts/staking/test/unit_tests/lib_fixed_math_test.ts index ae020ebc4d..8b08e74e41 100644 --- a/contracts/staking/test/unit_tests/lib_fixed_math_test.ts +++ b/contracts/staking/test/unit_tests/lib_fixed_math_test.ts @@ -1,8 +1,9 @@ import { blockchainTests, expect, hexRandom, Numberish } from '@0x/contracts-test-utils'; -import { BigNumber, FixedMathRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import { Decimal } from 'decimal.js'; import * as _ from 'lodash'; +import FixedMathRevertErrors = require('../../src/fixed_math_revert_errors'); import { assertRoughlyEquals, fromFixed, toDecimal, toFixed } from '../utils/number_utils'; import { artifacts } from '../artifacts'; diff --git a/contracts/staking/test/unit_tests/lib_safe_downcast_test.ts b/contracts/staking/test/unit_tests/lib_safe_downcast_test.ts index c04f1fe2e6..a5e56c924a 100644 --- a/contracts/staking/test/unit_tests/lib_safe_downcast_test.ts +++ b/contracts/staking/test/unit_tests/lib_safe_downcast_test.ts @@ -1,5 +1,6 @@ import { blockchainTests, expect, Numberish } from '@0x/contracts-test-utils'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { SafeMathRevertErrors } from '@0x/contracts-utils'; +import { BigNumber } from '@0x/utils'; import { artifacts } from '../artifacts'; import { TestLibSafeDowncastContract } from '../wrappers'; diff --git a/contracts/staking/test/unit_tests/mixin_scheduler_test.ts b/contracts/staking/test/unit_tests/mixin_scheduler_test.ts index 7c032727b8..8e01f061cd 100644 --- a/contracts/staking/test/unit_tests/mixin_scheduler_test.ts +++ b/contracts/staking/test/unit_tests/mixin_scheduler_test.ts @@ -1,9 +1,9 @@ import { blockchainTests, constants, expect, verifyEventsFromLogs } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import { LogWithDecodedArgs } from 'ethereum-types'; import { constants as stakingConstants } from '../../src/constants'; +import StakingRevertErrors = require('../../src/staking_revert_errors'); import { artifacts } from '../artifacts'; import { diff --git a/contracts/staking/test/unit_tests/mixin_stake_storage_test.ts b/contracts/staking/test/unit_tests/mixin_stake_storage_test.ts index 6167f75324..c3d85c148e 100644 --- a/contracts/staking/test/unit_tests/mixin_stake_storage_test.ts +++ b/contracts/staking/test/unit_tests/mixin_stake_storage_test.ts @@ -1,10 +1,11 @@ import { blockchainTests, expect, Numberish } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import { constants } from '../../src/constants'; import { StoredBalance } from '../../src/types'; +import { StakingRevertErrors } from '../../src'; + import { artifacts } from '../artifacts'; import { TestMixinStakeStorageContract } from '../wrappers'; diff --git a/contracts/staking/test/unit_tests/params_test.ts b/contracts/staking/test/unit_tests/params_test.ts index ce518e98de..c933242dcc 100644 --- a/contracts/staking/test/unit_tests/params_test.ts +++ b/contracts/staking/test/unit_tests/params_test.ts @@ -1,5 +1,6 @@ import { blockchainTests, expect, filterLogsToArguments } from '@0x/contracts-test-utils'; -import { AuthorizableRevertErrors, BigNumber } from '@0x/utils'; +import { AuthorizableRevertErrors } from '@0x/contracts-utils'; +import { BigNumber } from '@0x/utils'; import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; diff --git a/contracts/staking/test/unit_tests/protocol_fees_test.ts b/contracts/staking/test/unit_tests/protocol_fees_test.ts index 06a52f7d14..06634c5667 100644 --- a/contracts/staking/test/unit_tests/protocol_fees_test.ts +++ b/contracts/staking/test/unit_tests/protocol_fees_test.ts @@ -7,11 +7,12 @@ import { Numberish, randomAddress, } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import { LogEntry } from 'ethereum-types'; import * as _ from 'lodash'; +import StakingRevertErrors = require('../../src/staking_revert_errors'); + import { artifacts } from '../artifacts'; import { IStakingEventsEvents, diff --git a/contracts/staking/test/unit_tests/stake_balances_test.ts b/contracts/staking/test/unit_tests/stake_balances_test.ts index 44d625fe2f..26b347806b 100644 --- a/contracts/staking/test/unit_tests/stake_balances_test.ts +++ b/contracts/staking/test/unit_tests/stake_balances_test.ts @@ -6,7 +6,8 @@ import { hexRandom, randomAddress, } from '@0x/contracts-test-utils'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { SafeMathRevertErrors } from '@0x/contracts-utils'; +import { BigNumber } from '@0x/utils'; import { artifacts } from '../artifacts'; import { TestMixinStakeBalancesContract } from '../wrappers'; diff --git a/contracts/staking/test/unit_tests/stake_test.ts b/contracts/staking/test/unit_tests/stake_test.ts index d3d56af949..defd6b58d6 100644 --- a/contracts/staking/test/unit_tests/stake_test.ts +++ b/contracts/staking/test/unit_tests/stake_test.ts @@ -9,10 +9,10 @@ import { Numberish, shortZip, } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; +import StakingRevertErrors = require('../../src/staking_revert_errors'); import { StakeStatus } from '../../src/types'; import { artifacts } from '../artifacts'; diff --git a/contracts/staking/test/unit_tests/staking_pool_test.ts b/contracts/staking/test/unit_tests/staking_pool_test.ts index 84b349bcac..ca86db4988 100644 --- a/contracts/staking/test/unit_tests/staking_pool_test.ts +++ b/contracts/staking/test/unit_tests/staking_pool_test.ts @@ -8,10 +8,12 @@ import { toHex, verifyEventsFromLogs, } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { SafeMathRevertErrors } from '@0x/contracts-utils'; +import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; +import { StakingRevertErrors } from '../../src'; + import { artifacts } from '../artifacts'; import { TestMixinStakingPoolContract, diff --git a/contracts/staking/test/unit_tests/staking_proxy_test.ts b/contracts/staking/test/unit_tests/staking_proxy_test.ts index 915b6952ed..5d72266ca2 100644 --- a/contracts/staking/test/unit_tests/staking_proxy_test.ts +++ b/contracts/staking/test/unit_tests/staking_proxy_test.ts @@ -1,6 +1,6 @@ import { blockchainTests, constants, expect, verifyEventsFromLogs } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; -import { AuthorizableRevertErrors, BigNumber } from '@0x/utils'; +import { AuthorizableRevertErrors } from '@0x/contracts-utils'; +import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import { artifacts } from '../artifacts'; @@ -12,6 +12,7 @@ import { } from '../wrappers'; import { constants as stakingConstants } from '../../src/constants'; +import StakingRevertErrors = require('../../src/staking_revert_errors'); blockchainTests.resets('StakingProxy unit tests', env => { const testString = 'Hello, World!'; diff --git a/contracts/staking/test/unit_tests/zrx_vault_test.ts b/contracts/staking/test/unit_tests/zrx_vault_test.ts index 099f3e5fda..fc94715ac5 100644 --- a/contracts/staking/test/unit_tests/zrx_vault_test.ts +++ b/contracts/staking/test/unit_tests/zrx_vault_test.ts @@ -8,12 +8,13 @@ import { filterLogsToArguments, provider, } from '@0x/contracts-test-utils'; -import { StakingRevertErrors } from '@0x/order-utils'; +import { AuthorizableRevertErrors, SafeMathRevertErrors } from '@0x/contracts-utils'; import { RevertReason } from '@0x/types'; -import { AuthorizableRevertErrors, BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import { constants as stakingConstants } from '../../src/constants'; +import StakingRevertErrors = require('../../src/staking_revert_errors'); import { artifacts } from '../artifacts'; import { diff --git a/contracts/test-utils/CHANGELOG.json b/contracts/test-utils/CHANGELOG.json index 4616928b39..545e3b207e 100644 --- a/contracts/test-utils/CHANGELOG.json +++ b/contracts/test-utils/CHANGELOG.json @@ -6,6 +6,10 @@ "note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils", "pr": 2330 }, + { + "note": "Add new exports orderHashUtils and transactionHashUtils", + "pr": 2321 + }, { "note": "Remove TransactionHelper and MutatorContractFunction", "pr": 2325 diff --git a/contracts/test-utils/package.json b/contracts/test-utils/package.json index c6d4f2669b..9775484dda 100644 --- a/contracts/test-utils/package.json +++ b/contracts/test-utils/package.json @@ -42,9 +42,11 @@ "typescript": "3.0.1" }, "dependencies": { + "@0x/assert": "2.2.0-beta.1", + "@0x/dev-utils": "2.4.0-beta.1", "@0x/base-contract": "^5.5.0-beta.0", - "@0x/dev-utils": "^2.4.0-beta.1", "@0x/order-utils": "^8.5.0-beta.1", + "@0x/json-schemas": "4.1.0-beta.1", "@0x/sol-coverage": "^3.1.0-beta.1", "@0x/sol-profiler": "^3.2.0-beta.1", "@0x/sol-trace": "^2.1.0-beta.1", diff --git a/contracts/test-utils/src/index.ts b/contracts/test-utils/src/index.ts index 75d9f26840..ea304a3afe 100644 --- a/contracts/test-utils/src/index.ts +++ b/contracts/test-utils/src/index.ts @@ -72,3 +72,5 @@ export { getPercentageOfValue, toBaseUnitAmount, } from './number_utils'; +export { orderHashUtils } from './order_hash'; +export { transactionHashUtils } from './transaction_hash'; diff --git a/contracts/test-utils/src/order_factory.ts b/contracts/test-utils/src/order_factory.ts index 04e3adab1c..767fa697be 100644 --- a/contracts/test-utils/src/order_factory.ts +++ b/contracts/test-utils/src/order_factory.ts @@ -1,9 +1,10 @@ -import { generatePseudoRandomSalt, orderHashUtils } from '@0x/order-utils'; +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 { diff --git a/packages/order-utils/src/order_hash.ts b/contracts/test-utils/src/order_hash.ts similarity index 60% rename from packages/order-utils/src/order_hash.ts rename to contracts/test-utils/src/order_hash.ts index ce7e6d85f7..7470c3b2da 100644 --- a/packages/order-utils/src/order_hash.ts +++ b/contracts/test-utils/src/order_hash.ts @@ -1,30 +1,15 @@ -import { schemas, SchemaValidator } from '@0x/json-schemas'; +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'; -import { assert } from './assert'; -import { constants } from './constants'; -import { eip712Utils } from './eip712_utils'; - const INVALID_TAKER_FORMAT = 'instance.takerAddress is not of a type(s) string'; +const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'; + export const orderHashUtils = { - /** - * Checks if the supplied hex encoded order hash is valid. - * Note: Valid means it has the expected format, not that an order with the orderHash exists. - * Use this method when processing orderHashes submitted as user input. - * @param orderHash Hex encoded orderHash. - * @return Whether the supplied orderHash has the expected format. - */ - isValidOrderHash(orderHash: string): boolean { - // Since this method can be called to check if any arbitrary string conforms to an orderHash's - // format, we only assert that we were indeed passed a string. - assert.isString('orderHash', orderHash); - const schemaValidator = new SchemaValidator(); - const isValid = schemaValidator.validate(orderHash, schemas.orderHashSchema).valid; - return isValid; - }, /** * Computes the orderHash for a supplied order. * @param order An object that conforms to the Order or SignedOrder interface definitions. @@ -35,9 +20,7 @@ export const orderHashUtils = { 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 ${ - constants.NULL_ADDRESS - }`; + 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; @@ -57,9 +40,7 @@ export const orderHashUtils = { 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 ${ - constants.NULL_ADDRESS - }`; + 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; diff --git a/contracts/test-utils/src/transaction_factory.ts b/contracts/test-utils/src/transaction_factory.ts index 29edfcb0d6..69e7943cc1 100644 --- a/contracts/test-utils/src/transaction_factory.ts +++ b/contracts/test-utils/src/transaction_factory.ts @@ -1,8 +1,10 @@ -import { generatePseudoRandomSalt, transactionHashUtils } from '@0x/order-utils'; +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'; diff --git a/packages/order-utils/src/transaction_hash.ts b/contracts/test-utils/src/transaction_hash.ts similarity index 59% rename from packages/order-utils/src/transaction_hash.ts rename to contracts/test-utils/src/transaction_hash.ts index 2b2345af7c..718eca9111 100644 --- a/packages/order-utils/src/transaction_hash.ts +++ b/contracts/test-utils/src/transaction_hash.ts @@ -1,27 +1,11 @@ -import { schemas, SchemaValidator } from '@0x/json-schemas'; +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'; -import { assert } from './assert'; -import { eip712Utils } from './eip712_utils'; - export const transactionHashUtils = { - /** - * Checks if the supplied hex encoded 0x transaction hash is valid. - * Note: Valid means it has the expected format, not that a transaction with the transactionHash exists. - * Use this method when processing transactionHashes submitted as user input. - * @param transactionHash Hex encoded transactionHash. - * @return Whether the supplied transactionHash has the expected format. - */ - isValidTransactionHash(transactionHash: string): boolean { - // Since this method can be called to check if any arbitrary string conforms to an transactionHash's - // format, we only assert that we were indeed passed a string. - assert.isString('transactionHash', transactionHash); - const schemaValidator = new SchemaValidator(); - const isValid = schemaValidator.validate(transactionHash, schemas.orderHashSchema).valid; - return isValid; - }, /** * Computes the transactionHash for a supplied 0x transaction. * @param transaction An object that conforms to the ZeroExTransaction or SignedZeroExTransaction interface definitions. diff --git a/packages/order-utils/test/order_hash_test.ts b/contracts/test-utils/test/order_hash_test.ts similarity index 79% rename from packages/order-utils/test/order_hash_test.ts rename to contracts/test-utils/test/order_hash_test.ts index afcc5a0808..edc5930bee 100644 --- a/packages/order-utils/test/order_hash_test.ts +++ b/contracts/test-utils/test/order_hash_test.ts @@ -1,3 +1,4 @@ +import { chaiSetup } from '@0x/dev-utils'; import { Order } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; @@ -7,8 +8,6 @@ import { orderHashUtils } from '../src'; import { constants } from '../src/constants'; -import { chaiSetup } from './utils/chai_setup'; - chaiSetup.configure(); const expect = chai.expect; @@ -64,19 +63,4 @@ describe('Order hashing', () => { expect(() => orderHashUtils.getOrderHashHex(orderWithInvalidtakerFormat)).to.throw(expectedErrorMessage); }); }); - describe('#isValidOrderHash', () => { - it('returns false if the value is not a hex string', () => { - const isValid = orderHashUtils.isValidOrderHash('not a hex'); - expect(isValid).to.be.false(); - }); - it('returns false if the length is wrong', () => { - const isValid = orderHashUtils.isValidOrderHash('0xdeadbeef'); - expect(isValid).to.be.false(); - }); - it('returns true if order hash is correct', () => { - const orderHashLength = 65; - const isValid = orderHashUtils.isValidOrderHash(`0x${Array(orderHashLength).join('0')}`); - expect(isValid).to.be.true(); - }); - }); }); diff --git a/packages/order-utils/test/transaction_hash_test.ts b/contracts/test-utils/test/transaction_hash.ts similarity index 71% rename from packages/order-utils/test/transaction_hash_test.ts rename to contracts/test-utils/test/transaction_hash.ts index 56975658f7..fd5cb287f8 100644 --- a/packages/order-utils/test/transaction_hash_test.ts +++ b/contracts/test-utils/test/transaction_hash.ts @@ -1,3 +1,4 @@ +import { chaiSetup } from '@0x/dev-utils'; import { ZeroExTransaction } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; @@ -7,8 +8,6 @@ import { transactionHashUtils } from '../src'; import { constants } from '../src/constants'; -import { chaiSetup } from './utils/chai_setup'; - chaiSetup.configure(); const expect = chai.expect; @@ -46,19 +45,4 @@ describe('0x transaction hashing', () => { expect(transactionHash).to.be.equal(expectedTransactionHash); }); }); - describe('#isValidTransactionHash', () => { - it('returns false if the value is not a hex string', () => { - const isValid = transactionHashUtils.isValidTransactionHash('not a hex'); - expect(isValid).to.be.false(); - }); - it('returns false if the length is wrong', () => { - const isValid = transactionHashUtils.isValidTransactionHash('0xdeadbeef'); - expect(isValid).to.be.false(); - }); - it('returns true if order hash is correct', () => { - const orderHashLength = 65; - const isValid = transactionHashUtils.isValidTransactionHash(`0x${Array(orderHashLength).join('0')}`); - expect(isValid).to.be.true(); - }); - }); }); diff --git a/contracts/tests/test/dev-utils/get_order_hash.ts b/contracts/tests/test/dev-utils/get_order_hash.ts new file mode 100644 index 0000000000..5dc6185145 --- /dev/null +++ b/contracts/tests/test/dev-utils/get_order_hash.ts @@ -0,0 +1,41 @@ +import { DevUtilsContract } from '@0x/contracts-dev-utils/lib/generated-wrappers/dev_utils'; +import { Order } from '@0x/types'; +import { BigNumber } from '@0x/utils'; +import { chaiSetup } from '@0x/contracts-test-utils'; +import { SupportedProvider } from 'ethereum-types'; + +import * as chai from 'chai'; +chaiSetup.configure(); +const expect = chai.expect; + +const NULL_ADDRESS = '0x' + '00'.repeat(20); + +describe('DevUtils.getOrderHash', () => { + it('should return the order hash', async () => { + const expectedOrderHash = '0x331cb7e07a757bae130702da6646c26531798c92bcfaf671817268fd2c188531'; + const exchangeAddress = '0x1dc4c1cefef38a777b15aa20260a54e584b16c48'; + const chainId = 50; + const order: Order = { + makerAddress: NULL_ADDRESS, + takerAddress: NULL_ADDRESS, + senderAddress: NULL_ADDRESS, + feeRecipientAddress: NULL_ADDRESS, + makerAssetData: NULL_ADDRESS, + takerAssetData: NULL_ADDRESS, + makerFeeAssetData: NULL_ADDRESS, + takerFeeAssetData: 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, + chainId, + }; + const devUtilsContract = new DevUtilsContract(NULL_ADDRESS, { isEIP1193: true } as SupportedProvider); + expect( + await devUtilsContract.getOrderHash(order, new BigNumber(chainId), exchangeAddress).callAsync(), + ).to.be.equal(expectedOrderHash); + }); +}); diff --git a/contracts/tests/test/dev-utils/lib_asset_data.ts b/contracts/tests/test/dev-utils/lib_asset_data.ts index ea54360bc4..76ebe8578a 100644 --- a/contracts/tests/test/dev-utils/lib_asset_data.ts +++ b/contracts/tests/test/dev-utils/lib_asset_data.ts @@ -26,7 +26,7 @@ import { BigNumber, providerUtils, StringRevertError } from '@0x/utils'; import * as ethUtil from 'ethereumjs-util'; import { artifacts, LibAssetDataContract } from '@0x/contracts-dev-utils'; -import { InvalidByteOperationError } from '@0x/utils/lib/src/lib_bytes_revert_errors'; +import { InvalidByteOperationError } from '@0x/contracts-utils/lib/src/lib_bytes_revert_errors'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/tests/test/dev-utils/order_validation_utils.ts b/contracts/tests/test/dev-utils/order_validation_utils.ts index 282040e9b7..e8449ff2c8 100644 --- a/contracts/tests/test/dev-utils/order_validation_utils.ts +++ b/contracts/tests/test/dev-utils/order_validation_utils.ts @@ -12,6 +12,7 @@ import { artifacts as exchangeArtifacts, ExchangeContract } from '@0x/contracts- import { chaiSetup, constants, + orderHashUtils, OrderFactory, OrderStatus, provider, @@ -19,7 +20,6 @@ import { web3Wrapper, } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; -import { orderHashUtils } from '@0x/order-utils'; import { OrderTransferResults, SignedOrder } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import * as chai from 'chai'; diff --git a/contracts/utils/CHANGELOG.json b/contracts/utils/CHANGELOG.json index 2310b0900a..5527467c0c 100644 --- a/contracts/utils/CHANGELOG.json +++ b/contracts/utils/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils", "pr": 2330 + }, + { + "note": "Introduced new exports AuthorizableRevertErrors, LibAddressArrayRevertErrors, LibBytesRevertErrors, OwnableRevertErrors, ReentrancyGuardRevertErrors and SafeMathRevertErrors", + "pr": 2321 } ] }, diff --git a/packages/utils/src/authorizable_revert_errors.ts b/contracts/utils/src/authorizable_revert_errors.ts similarity index 94% rename from packages/utils/src/authorizable_revert_errors.ts rename to contracts/utils/src/authorizable_revert_errors.ts index a70c6e15db..dd001d5e44 100644 --- a/packages/utils/src/authorizable_revert_errors.ts +++ b/contracts/utils/src/authorizable_revert_errors.ts @@ -1,5 +1,4 @@ -import { BigNumber } from './configured_bignumber'; -import { RevertError } from './revert_error'; +import { BigNumber, RevertError } from '@0x/utils'; // tslint:disable:max-classes-per-file export class AuthorizedAddressMismatchError extends RevertError { diff --git a/contracts/utils/src/index.ts b/contracts/utils/src/index.ts index 0233c608d1..4f155f1863 100644 --- a/contracts/utils/src/index.ts +++ b/contracts/utils/src/index.ts @@ -3,3 +3,10 @@ export * from './wrappers'; import * as ReferenceFunctionsToExport from './reference_functions'; export import ReferenceFunctions = ReferenceFunctionsToExport; + +export import AuthorizableRevertErrors = require('./authorizable_revert_errors'); +export import LibAddressArrayRevertErrors = require('./lib_address_array_revert_errors'); +export import LibBytesRevertErrors = require('./lib_bytes_revert_errors'); +export import OwnableRevertErrors = require('./ownable_revert_errors'); +export import ReentrancyGuardRevertErrors = require('./reentrancy_guard_revert_errors'); +export import SafeMathRevertErrors = require('./safe_math_revert_errors'); diff --git a/packages/utils/src/lib_address_array_revert_errors.ts b/contracts/utils/src/lib_address_array_revert_errors.ts similarity index 80% rename from packages/utils/src/lib_address_array_revert_errors.ts rename to contracts/utils/src/lib_address_array_revert_errors.ts index f80ab28a6f..fdd7c4fbcd 100644 --- a/packages/utils/src/lib_address_array_revert_errors.ts +++ b/contracts/utils/src/lib_address_array_revert_errors.ts @@ -1,5 +1,4 @@ -import { BigNumber } from './configured_bignumber'; -import { RevertError } from './revert_error'; +import { BigNumber, RevertError } from '@0x/utils'; export class MismanagedMemoryError extends RevertError { constructor(freeMemPtr?: BigNumber, addressArrayEndPtr?: BigNumber) { diff --git a/packages/utils/src/lib_bytes_revert_errors.ts b/contracts/utils/src/lib_bytes_revert_errors.ts similarity index 89% rename from packages/utils/src/lib_bytes_revert_errors.ts rename to contracts/utils/src/lib_bytes_revert_errors.ts index 31db1b18f6..3d7f4fa0f9 100644 --- a/packages/utils/src/lib_bytes_revert_errors.ts +++ b/contracts/utils/src/lib_bytes_revert_errors.ts @@ -1,5 +1,4 @@ -import { BigNumber } from './configured_bignumber'; -import { RevertError } from './revert_error'; +import { BigNumber, RevertError } from '@0x/utils'; export enum InvalidByteOperationErrorCodes { FromLessThanOrEqualsToRequired, diff --git a/packages/utils/src/ownable_revert_errors.ts b/contracts/utils/src/ownable_revert_errors.ts similarity index 93% rename from packages/utils/src/ownable_revert_errors.ts rename to contracts/utils/src/ownable_revert_errors.ts index 14682cce88..dd61036876 100644 --- a/packages/utils/src/ownable_revert_errors.ts +++ b/contracts/utils/src/ownable_revert_errors.ts @@ -1,4 +1,4 @@ -import { RevertError } from './revert_error'; +import { RevertError } from '@0x/utils'; // tslint:disable:max-classes-per-file export class OnlyOwnerError extends RevertError { diff --git a/packages/utils/src/reentrancy_guard_revert_errors.ts b/contracts/utils/src/reentrancy_guard_revert_errors.ts similarity index 84% rename from packages/utils/src/reentrancy_guard_revert_errors.ts rename to contracts/utils/src/reentrancy_guard_revert_errors.ts index 828dc2bb77..1c39c6d5c4 100644 --- a/packages/utils/src/reentrancy_guard_revert_errors.ts +++ b/contracts/utils/src/reentrancy_guard_revert_errors.ts @@ -1,4 +1,4 @@ -import { RevertError } from './revert_error'; +import { RevertError } from '@0x/utils'; export class IllegalReentrancyError extends RevertError { constructor() { diff --git a/contracts/utils/src/reference_functions.ts b/contracts/utils/src/reference_functions.ts index cd67f4a089..3b384fb71f 100644 --- a/contracts/utils/src/reference_functions.ts +++ b/contracts/utils/src/reference_functions.ts @@ -1,4 +1,6 @@ -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; + +import SafeMathRevertErrors = require('./safe_math_revert_errors'); const MAX_UINT256 = new BigNumber(2).pow(256).minus(1); diff --git a/packages/utils/src/safe_math_revert_errors.ts b/contracts/utils/src/safe_math_revert_errors.ts similarity index 94% rename from packages/utils/src/safe_math_revert_errors.ts rename to contracts/utils/src/safe_math_revert_errors.ts index 2d0bce62ea..499dc2009e 100644 --- a/packages/utils/src/safe_math_revert_errors.ts +++ b/contracts/utils/src/safe_math_revert_errors.ts @@ -1,5 +1,4 @@ -import { BigNumber } from './configured_bignumber'; -import { RevertError } from './revert_error'; +import { BigNumber, RevertError } from '@0x/utils'; // tslint:disable:max-classes-per-file diff --git a/contracts/utils/test/authorizable.ts b/contracts/utils/test/authorizable.ts index a7069200b8..26a71b337e 100644 --- a/contracts/utils/test/authorizable.ts +++ b/contracts/utils/test/authorizable.ts @@ -1,9 +1,12 @@ import { chaiSetup, constants, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; -import { AuthorizableRevertErrors, BigNumber, OwnableRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; +import AuthorizableRevertErrors = require('../src/authorizable_revert_errors'); +import OwnableRevertErrors = require('../src/ownable_revert_errors'); + import { artifacts } from './artifacts'; import { AuthorizableContract } from './wrappers'; diff --git a/contracts/utils/test/lib_address_array.ts b/contracts/utils/test/lib_address_array.ts index df4116b661..de256709bb 100644 --- a/contracts/utils/test/lib_address_array.ts +++ b/contracts/utils/test/lib_address_array.ts @@ -1,9 +1,11 @@ import { chaiSetup, provider, randomAddress, txDefaults, web3Wrapper } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; -import { BigNumber, LibAddressArrayRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; +import LibAddressArrayRevertErrors = require('../src/lib_address_array_revert_errors'); + import { artifacts } from './artifacts'; import { TestLibAddressArrayContract } from './wrappers'; diff --git a/contracts/utils/test/lib_bytes.ts b/contracts/utils/test/lib_bytes.ts index e8feeb61d0..ea55d7cff2 100644 --- a/contracts/utils/test/lib_bytes.ts +++ b/contracts/utils/test/lib_bytes.ts @@ -1,9 +1,11 @@ import { blockchainTests, constants, expect } from '@0x/contracts-test-utils'; -import { BigNumber, LibBytesRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import BN = require('bn.js'); import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; +import LibBytesRevertErrors = require('../src/lib_bytes_revert_errors'); + import { artifacts } from './artifacts'; import { TestLibBytesContract } from './wrappers'; diff --git a/contracts/utils/test/lib_safe_math.ts b/contracts/utils/test/lib_safe_math.ts index f6a34c391f..42121106d0 100644 --- a/contracts/utils/test/lib_safe_math.ts +++ b/contracts/utils/test/lib_safe_math.ts @@ -1,8 +1,9 @@ import { blockchainTests, constants, describe, expect } from '@0x/contracts-test-utils'; -import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import * as ReferenceFunctions from '../src/reference_functions'; +import SafeMathRevertErrors = require('../src/safe_math_revert_errors'); import { artifacts } from './artifacts'; import { TestLibSafeMathContract } from './wrappers'; diff --git a/contracts/utils/test/ownable.ts b/contracts/utils/test/ownable.ts index 471edcd9a5..e802a0b679 100644 --- a/contracts/utils/test/ownable.ts +++ b/contracts/utils/test/ownable.ts @@ -1,5 +1,6 @@ import { blockchainTests, constants, expect, filterLogsToArguments } from '@0x/contracts-test-utils'; -import { OwnableRevertErrors } from '@0x/utils'; + +import OwnableRevertErrors = require('../src/ownable_revert_errors'); import { artifacts } from './artifacts'; import { IOwnableEvents, IOwnableOwnershipTransferredEventArgs, TestOwnableContract } from './wrappers'; diff --git a/contracts/utils/test/reentrancy_guard.ts b/contracts/utils/test/reentrancy_guard.ts index 186549500f..438fccf63a 100644 --- a/contracts/utils/test/reentrancy_guard.ts +++ b/contracts/utils/test/reentrancy_guard.ts @@ -1,9 +1,10 @@ import { chaiSetup, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; -import { ReentrancyGuardRevertErrors } from '@0x/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; +import ReentrancyGuardRevertErrors = require('../src/reentrancy_guard_revert_errors'); + import { artifacts } from './artifacts'; import { TestReentrancyGuardContract } from './wrappers'; diff --git a/contracts/utils/test/reference_functions.ts b/contracts/utils/test/reference_functions.ts index f604633e2b..4b6393715b 100644 --- a/contracts/utils/test/reference_functions.ts +++ b/contracts/utils/test/reference_functions.ts @@ -1,7 +1,7 @@ import { constants, describe, expect } from '@0x/contracts-test-utils'; -import { SafeMathRevertErrors } from '@0x/utils'; import { safeAdd, safeDiv, safeMul, safeSub } from '../src/reference_functions'; +import SafeMathRevertErrors = require('../src/safe_math_revert_errors'); describe('Reference Functions', () => { const { ONE_ETHER, MAX_UINT256, ZERO_AMOUNT } = constants; diff --git a/package.json b/package.json index 86e0e812b1..f10ca3d81b 100644 --- a/package.json +++ b/package.json @@ -61,11 +61,11 @@ "files": [ { "path": "packages/0x.js/_bundles/index.min.js", - "maxSize": "1260kB" + "maxSize": "1300kB" }, { "path": "packages/instant/umd/instant.js", - "maxSize": "1960kB" + "maxSize": "2100kB" } ], "ci": { diff --git a/packages/0x.js/CHANGELOG.json b/packages/0x.js/CHANGELOG.json index a60813ba14..ec00c197d7 100644 --- a/packages/0x.js/CHANGELOG.json +++ b/packages/0x.js/CHANGELOG.json @@ -17,6 +17,10 @@ { "note": "Remove IWallet and IValidator contract wrappers", "pr": 2337 + }, + { + "note": "Remove exports orderHashUtils and transactionHashUtils", + "pr": 2321 } ] }, diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index 9eeba88af5..1e385abf1f 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -1,12 +1,6 @@ export { getContractAddressesForChainOrThrow, ChainId, ContractAddresses } from '@0x/contract-addresses'; -export { - assetDataUtils, - signatureUtils, - generatePseudoRandomSalt, - orderHashUtils, - transactionHashUtils, -} from '@0x/order-utils'; +export { assetDataUtils, signatureUtils, generatePseudoRandomSalt } from '@0x/order-utils'; export { ExchangeEventArgs, diff --git a/packages/connect/CHANGELOG.json b/packages/connect/CHANGELOG.json index 17c0652fac..c7404b8450 100644 --- a/packages/connect/CHANGELOG.json +++ b/packages/connect/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "5.1.0-beta.2", + "changes": [ + { + "note": "Removed dependency on @0x/order-utils", + "pr": 2321 + } + ] + }, { "version": "5.1.0-beta.1", "changes": [ diff --git a/packages/connect/package.json b/packages/connect/package.json index aad08f11d0..5852f53e78 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -50,7 +50,6 @@ "dependencies": { "@0x/assert": "^2.2.0-beta.1", "@0x/json-schemas": "^4.1.0-beta.1", - "@0x/order-utils": "^8.5.0-beta.1", "@0x/types": "^2.5.0-beta.1", "@0x/typescript-typings": "^4.4.0-beta.1", "@0x/utils": "^4.6.0-beta.1", diff --git a/packages/order-utils/src/parsing_utils.ts b/packages/connect/src/utils/order_parsing_utils.ts similarity index 100% rename from packages/order-utils/src/parsing_utils.ts rename to packages/connect/src/utils/order_parsing_utils.ts diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts index 2b1a658d1c..6f416b55de 100644 --- a/packages/connect/src/utils/relayer_response_json_parsers.ts +++ b/packages/connect/src/utils/relayer_response_json_parsers.ts @@ -1,7 +1,5 @@ import { assert } from '@0x/assert'; import { schemas } from '@0x/json-schemas'; -import { orderParsingUtils } from '@0x/order-utils'; - import { APIOrder, AssetPairsItem, @@ -11,6 +9,7 @@ import { OrdersResponse, } from '@0x/types'; +import { orderParsingUtils } from './order_parsing_utils'; import { typeConverters } from './type_converters'; export const relayerResponseJsonParsers = { diff --git a/packages/connect/src/utils/type_converters.ts b/packages/connect/src/utils/type_converters.ts index b262a516b2..1be06a6ecc 100644 --- a/packages/connect/src/utils/type_converters.ts +++ b/packages/connect/src/utils/type_converters.ts @@ -1,8 +1,9 @@ -import { orderParsingUtils } from '@0x/order-utils'; import * as _ from 'lodash'; import { APIOrder } from '@0x/types'; +import { orderParsingUtils } from './order_parsing_utils'; + export const typeConverters = { convertOrderbookStringFieldsToBigNumber(orderbook: any): any { const bids = _.get(orderbook, 'bids', []); diff --git a/packages/order-utils/CHANGELOG.json b/packages/order-utils/CHANGELOG.json index c5bb757eb5..d3985d5d77 100644 --- a/packages/order-utils/CHANGELOG.json +++ b/packages/order-utils/CHANGELOG.json @@ -5,6 +5,18 @@ { "note": "[Breaking] Removed `OrderStateUtils`, `OrderValidationUtils`, `ExchangeTransferSimulator` and all abstract and store classes. For order validation, please use the `DevUtils` contract wrapper method `getOrderRelevantState`|`getOrderRelevantStates`", "pr": 2324 + }, + { + "note": "Removed exports CoordinatorRevertErrors, ExchangeRevertErrors, ForwarderRevertErrors, LibMathRevertErrors, orderHashUtils, orderParsingUtils, StakingRevertErrors and transactionHashUtils", + "pr": 2321 + }, + { + "note": "Removed many functions from export signatureUtils", + "pr": 2321 + }, + { + "note": "Removed function isValidOrderHash from export orderHashUtils", + "pr": 2321 } ] }, diff --git a/packages/order-utils/package.json b/packages/order-utils/package.json index 0f9959c6d0..ba60e5b34f 100644 --- a/packages/order-utils/package.json +++ b/packages/order-utils/package.json @@ -63,6 +63,7 @@ "@0x/assert": "^2.2.0-beta.1", "@0x/contract-addresses": "^3.3.0-beta.2", "@0x/contract-artifacts": "^2.3.0-beta.2", + "@0x/contracts-dev-utils": "^0.1.0-beta.1", "@0x/json-schemas": "^4.1.0-beta.1", "@0x/types": "^2.5.0-beta.1", "@0x/typescript-typings": "^4.4.0-beta.1", diff --git a/packages/order-utils/src/eip712_utils.ts b/packages/order-utils/src/eip712_utils.ts index 0370db9d97..b31a37ae8d 100644 --- a/packages/order-utils/src/eip712_utils.ts +++ b/packages/order-utils/src/eip712_utils.ts @@ -1,4 +1,5 @@ import { assert } from '@0x/assert'; +import { DevUtilsContract } from '@0x/contracts-dev-utils'; import { schemas } from '@0x/json-schemas'; import { EIP712DomainWithDefaultSchema, @@ -9,10 +10,10 @@ import { SignedZeroExTransaction, ZeroExTransaction, } from '@0x/types'; +import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import { constants } from './constants'; -import { transactionHashUtils } from './transaction_hash'; export const eip712Utils = { /** @@ -100,18 +101,26 @@ export const eip712Utils = { * @param txOrigin The desired `tx.origin` that should be able to submit an Ethereum txn involving this 0x transaction * @return A typed data object */ - createCoordinatorApprovalTypedData: ( + async createCoordinatorApprovalTypedDataAsync( transaction: SignedZeroExTransaction, verifyingContract: string, txOrigin: string, - ): EIP712TypedData => { + ): Promise { const domain = { ...transaction.domain, name: constants.COORDINATOR_DOMAIN_NAME, version: constants.COORDINATOR_DOMAIN_VERSION, verifyingContract, }; - const transactionHash = transactionHashUtils.getTransactionHashHex(transaction); + const transactionHash = await new DevUtilsContract('0x0000000000000000000000000000000000000000', { + isEIP1193: true, + } as any) + .getTransactionHash( + transaction, + new BigNumber(transaction.domain.chainId), + transaction.domain.verifyingContract, + ) + .callAsync(); const approval = { txOrigin, transactionHash, diff --git a/packages/order-utils/src/index.ts b/packages/order-utils/src/index.ts index 2c05a038fd..dc8f5067e5 100644 --- a/packages/order-utils/src/index.ts +++ b/packages/order-utils/src/index.ts @@ -1,18 +1,9 @@ -export import CoordinatorRevertErrors = require('./coordinator_revert_errors'); -export import ExchangeRevertErrors = require('./exchange_revert_errors'); -export import ForwarderRevertErrors = require('./forwarder_revert_errors'); -export import LibMathRevertErrors = require('./lib_math_revert_errors'); -export import StakingRevertErrors = require('./staking_revert_errors'); - -export { orderHashUtils } from './order_hash'; export { signatureUtils } from './signature_utils'; export { generatePseudoRandomSalt } from './salt'; export { assetDataUtils } from './asset_data_utils'; export { marketUtils } from './market_utils'; -export { transactionHashUtils } from './transaction_hash'; export { rateUtils } from './rate_utils'; export { sortingUtils } from './sorting_utils'; -export { orderParsingUtils } from './parsing_utils'; export { orderCalculationUtils } from './order_calculation_utils'; export { eip712Utils } from './eip712_utils'; diff --git a/packages/order-utils/src/order_factory.ts b/packages/order-utils/src/order_factory.ts index fe8c376d5e..46d34c3a8f 100644 --- a/packages/order-utils/src/order_factory.ts +++ b/packages/order-utils/src/order_factory.ts @@ -1,10 +1,10 @@ +import { DevUtilsContract } from '@0x/contracts-dev-utils'; import { Order, SignedOrder } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import { SupportedProvider } from 'ethereum-types'; import * as _ from 'lodash'; import { constants } from './constants'; -import { orderHashUtils } from './order_hash'; import { generatePseudoRandomSalt } from './salt'; import { signatureUtils } from './signature_utils'; import { CreateOrderOpts } from './types'; @@ -77,7 +77,11 @@ export const orderFactory = { await providerUtils.getChainIdAsync(supportedProvider), createOrderOpts, ); - const orderHash = orderHashUtils.getOrderHashHex(order); + const orderHash = await new DevUtilsContract('0x0000000000000000000000000000000000000000', { + isEIP1193: true, + } as any) + .getOrderHash(order, new BigNumber(order.chainId), order.exchangeAddress) + .callAsync(); const signature = await signatureUtils.ecSignHashAsync(supportedProvider, orderHash, makerAddress); const signedOrder: SignedOrder = _.assign(order, { signature }); return signedOrder; diff --git a/packages/order-utils/src/signature_utils.ts b/packages/order-utils/src/signature_utils.ts index 364f564c39..b75f079b4a 100644 --- a/packages/order-utils/src/signature_utils.ts +++ b/packages/order-utils/src/signature_utils.ts @@ -1,5 +1,4 @@ -import { ExchangeContract, IValidatorContract, IWalletContract } from '@0x/abi-gen-wrappers'; -import { getContractAddressesForChainOrThrow } from '@0x/contract-addresses'; +import { DevUtilsContract } from '@0x/contracts-dev-utils'; import { schemas } from '@0x/json-schemas'; import { ECSignature, @@ -10,233 +9,21 @@ import { ValidatorSignature, ZeroExTransaction, } from '@0x/types'; -import { providerUtils } from '@0x/utils'; +import { BigNumber, providerUtils } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { SupportedProvider } from 'ethereum-types'; import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; import { assert } from './assert'; -import { constants } from './constants'; import { eip712Utils } from './eip712_utils'; -import { orderHashUtils } from './order_hash'; -import { transactionHashUtils } from './transaction_hash'; import { TypedDataError } from './types'; -import { utils } from './utils'; + +const devUtilsContract = new DevUtilsContract('0x0000000000000000000000000000000000000000', { + isEIP1193: true, +} as any); export const signatureUtils = { - /** - * Verifies that the provided signature is valid according to the 0x Protocol smart contracts - * @param supportedProvider Web3 provider to use for all JSON RPC requests - * @param data The hex encoded data signed by the supplied signature. - * @param signature A hex encoded 0x Protocol signature made up of: [TypeSpecificData][SignatureType]. - * E.g [vrs][SignatureType.EIP712] - * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. - * @param exchangeAddress Optional address of the Exchange contract to validate the signature against. - * @return Whether the signature is valid for the supplied signerAddress and data. - */ - async isValidSignatureAsync( - supportedProvider: SupportedProvider, - data: string, - signature: string, - signerAddress: string, - exchangeAddress?: string, - ): Promise { - const provider = providerUtils.standardizeOrThrow(supportedProvider); - assert.isHexString('data', data); - assert.isHexString('signature', signature); - assert.isETHAddressHex('signerAddress', signerAddress); - const signatureTypeIndexIfExists = utils.getSignatureTypeIndexIfExists(signature); - if (signatureTypeIndexIfExists === undefined) { - throw new Error(`Unrecognized signatureType in signature: ${signature}`); - } - - switch (signatureTypeIndexIfExists) { - case SignatureType.Illegal: - case SignatureType.Invalid: - return false; - - case SignatureType.EIP712: { - const ecSignature = signatureUtils.parseECSignature(signature); - return signatureUtils.isValidECSignature(data, ecSignature, signerAddress); - } - - case SignatureType.EthSign: { - const ecSignature = signatureUtils.parseECSignature(signature); - const prefixedMessageHex = signatureUtils.addSignedMessagePrefix(data); - return signatureUtils.isValidECSignature(prefixedMessageHex, ecSignature, signerAddress); - } - - case SignatureType.Wallet: { - const isValid = await signatureUtils.isValidWalletSignatureAsync( - provider, - data, - signature, - signerAddress, - ); - return isValid; - } - - case SignatureType.Validator: { - const isValid = await signatureUtils.isValidValidatorSignatureAsync( - provider, - data, - signature, - signerAddress, - exchangeAddress, - ); - return isValid; - } - - case SignatureType.PreSigned: { - return signatureUtils.isValidPresignedSignatureAsync(provider, data, signerAddress, exchangeAddress); - } - - default: - throw new Error(`Unhandled SignatureType: ${signatureTypeIndexIfExists}`); - } - }, - /** - * Verifies that the provided presigned signature is valid according to the 0x Protocol smart contracts - * @param supportedProvider Web3 provider to use for all JSON RPC requests - * @param data The hex encoded data signed by the supplied signature - * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. - * @param exchangeAddress The address of the Exchange contract to validate the signature against. - * @return Whether the data was preSigned by the supplied signerAddress - */ - async isValidPresignedSignatureAsync( - supportedProvider: SupportedProvider, - data: string, - signerAddress: string, - exchangeAddress?: string, - ): Promise { - const provider = providerUtils.standardizeOrThrow(supportedProvider); - assert.isHexString('data', data); - assert.isETHAddressHex('signerAddress', signerAddress); - - let exchangeContract: ExchangeContract; - if (exchangeAddress !== undefined) { - assert.isETHAddressHex('exchange', exchangeAddress); - exchangeContract = new ExchangeContract(exchangeAddress, provider); - } else { - const web3Wrapper = new Web3Wrapper(provider); - const chainId = await web3Wrapper.getChainIdAsync(); - const addresses = getContractAddressesForChainOrThrow(chainId); - exchangeContract = new ExchangeContract(addresses.exchange, provider); - } - - const isValid = await exchangeContract.preSigned(data, signerAddress).callAsync(); - return isValid; - }, - /** - * Verifies that the provided wallet signature is valid according to the 0x Protocol smart contracts - * @param supportedProvider Web3 provider to use for all JSON RPC requests - * @param data The hex encoded data signed by the supplied signature. - * @param signature A hex encoded presigned 0x Protocol signature made up of: [SignatureType.Presigned] - * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. - * @return Whether the data was preSigned by the supplied signerAddress. - */ - async isValidWalletSignatureAsync( - supportedProvider: SupportedProvider, - data: string, - signature: string, - signerAddress: string, - ): Promise { - const provider = providerUtils.standardizeOrThrow(supportedProvider); - assert.isHexString('data', data); - assert.isHexString('signature', signature); - assert.isETHAddressHex('signerAddress', signerAddress); - // tslint:disable-next-line:custom-no-magic-numbers - const signatureWithoutType = signature.slice(0, -2); - const walletContract = new IWalletContract(signerAddress, provider); - try { - const magicValue = await walletContract.isValidSignature(data, signatureWithoutType).callAsync(); - return magicValue === constants.IS_VALID_WALLET_SIGNATURE_MAGIC_VALUE; - } catch (e) { - return false; - } - }, - /** - * Verifies that the provided validator signature is valid according to the 0x Protocol smart contracts - * @param supportedProvider Web3 provider to use for all JSON RPC requests - * @param data The hex encoded data signed by the supplied signature. - * @param signature A hex encoded presigned 0x Protocol signature made up of: [SignatureType.Presigned] - * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. - * @param exchangeAddress The address of the Exchange contract to validate the signature against. - * @return Whether the data was preSigned by the supplied signerAddress. - */ - async isValidValidatorSignatureAsync( - supportedProvider: SupportedProvider, - data: string, - signature: string, - signerAddress: string, - exchangeAddress?: string, - ): Promise { - const provider = providerUtils.standardizeOrThrow(supportedProvider); - assert.isHexString('data', data); - assert.isHexString('signature', signature); - assert.isETHAddressHex('signerAddress', signerAddress); - - let exchangeContract: ExchangeContract; - if (exchangeAddress !== undefined) { - assert.isETHAddressHex('exchange', exchangeAddress); - exchangeContract = new ExchangeContract(exchangeAddress, provider); - } else { - const web3Wrapper = new Web3Wrapper(provider); - const chainId = await web3Wrapper.getChainIdAsync(); - const addresses = getContractAddressesForChainOrThrow(chainId); - exchangeContract = new ExchangeContract(addresses.exchange, provider); - } - - const validatorSignature = signatureUtils.parseValidatorSignature(signature); - const isValidatorApproved = await exchangeContract - .allowedValidators(signerAddress, validatorSignature.validatorAddress) - .callAsync(); - if (!isValidatorApproved) { - throw new Error( - `Validator ${validatorSignature.validatorAddress} was not pre-approved by ${signerAddress}.`, - ); - } - - const validatorContract = new IValidatorContract(validatorSignature.validatorAddress, provider); - try { - const magicValue = await validatorContract - .isValidSignature(data, signerAddress, validatorSignature.signature) - .callAsync(); - return magicValue === constants.IS_VALID_VALIDATOR_SIGNATURE_MAGIC_VALUE; - } catch (e) { - return false; - } - }, - /** - * Checks if the supplied elliptic curve signature corresponds to signing `data` with - * the private key corresponding to `signerAddress` - * @param data The hex encoded data signed by the supplied signature. - * @param signature An object containing the elliptic curve signature parameters. - * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. - * @return Whether the ECSignature is valid. - */ - isValidECSignature(data: string, signature: ECSignature, signerAddress: string): boolean { - assert.isHexString('data', data); - assert.doesConformToSchema('signature', signature, schemas.ecSignatureSchema); - assert.isETHAddressHex('signerAddress', signerAddress); - const normalizedSignerAddress = signerAddress.toLowerCase(); - - const msgHashBuff = ethUtil.toBuffer(data); - try { - const pubKey = ethUtil.ecrecover( - msgHashBuff, - signature.v, - ethUtil.toBuffer(signature.r), - ethUtil.toBuffer(signature.s), - ); - const retrievedAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey)); - const normalizedRetrievedAddress = retrievedAddress.toLowerCase(); - return normalizedRetrievedAddress === normalizedSignerAddress; - } catch (err) { - return false; - } - }, /** * Signs an order and returns a SignedOrder. First `eth_signTypedData` is requested * then a fallback to `eth_sign` if not available on the supplied provider. @@ -264,7 +51,9 @@ export const signatureUtils = { if (err.message.includes('User denied message signature')) { throw err; } - const orderHash = orderHashUtils.getOrderHashHex(order); + const orderHash = await devUtilsContract + .getOrderHash(order, new BigNumber(order.chainId), order.exchangeAddress) + .callAsync(); const signatureHex = await signatureUtils.ecSignHashAsync(supportedProvider, orderHash, signerAddress); const signedOrder = { ...order, @@ -347,7 +136,13 @@ export const signatureUtils = { if (err.message.includes('User denied message signature')) { throw err; } - const transactionHash = transactionHashUtils.getTransactionHashHex(transaction); + const transactionHash = await devUtilsContract + .getTransactionHash( + transaction, + new BigNumber(transaction.domain.chainId), + transaction.domain.verifyingContract, + ) + .callAsync(); const signatureHex = await signatureUtils.ecSignHashAsync( supportedProvider, transactionHash, @@ -434,11 +229,7 @@ export const signatureUtils = { const validVParamValues = [27, 28]; const ecSignatureRSV = parseSignatureHexAsRSV(signature); if (_.includes(validVParamValues, ecSignatureRSV.v)) { - const isValidRSVSignature = signatureUtils.isValidECSignature( - prefixedMsgHashHex, - ecSignatureRSV, - normalizedSignerAddress, - ); + const isValidRSVSignature = isValidECSignature(prefixedMsgHashHex, ecSignatureRSV, normalizedSignerAddress); if (isValidRSVSignature) { const convertedSignatureHex = signatureUtils.convertECSignatureToSignatureHex(ecSignatureRSV); return convertedSignatureHex; @@ -446,11 +237,7 @@ export const signatureUtils = { } const ecSignatureVRS = parseSignatureHexAsVRS(signature); if (_.includes(validVParamValues, ecSignatureVRS.v)) { - const isValidVRSSignature = signatureUtils.isValidECSignature( - prefixedMsgHashHex, - ecSignatureVRS, - normalizedSignerAddress, - ); + const isValidVRSSignature = isValidECSignature(prefixedMsgHashHex, ecSignatureVRS, normalizedSignerAddress); if (isValidVRSSignature) { const convertedSignatureHex = signatureUtils.convertECSignatureToSignatureHex(ecSignatureVRS); return convertedSignatureHex; @@ -501,23 +288,6 @@ export const signatureUtils = { const prefixedMsgHex = ethUtil.bufferToHex(prefixedMsgBuff); return prefixedMsgHex; }, - /** - * Parse a 0x protocol hex-encoded signature string into its ECSignature components - * @param signature A hex encoded ecSignature 0x Protocol signature - * @return An ECSignature object with r,s,v parameters - */ - parseECSignature(signature: string): ECSignature { - assert.isHexString('signature', signature); - const ecSignatureTypes = [SignatureType.EthSign, SignatureType.EIP712]; - assert.isOneOfExpectedSignatureTypes(signature, ecSignatureTypes); - - // tslint:disable-next-line:custom-no-magic-numbers - const vrsHex = signature.slice(0, -2); - const ecSignature = parseSignatureHexAsVRS(vrsHex); - - return ecSignature; - }, - /** * Parse a hex-encoded Validator signature into validator address and signature components * @param signature A hex encoded Validator 0x Protocol signature @@ -535,7 +305,10 @@ export const signatureUtils = { }, }; -function parseSignatureHexAsVRS(signatureHex: string): ECSignature { +/** + * Parses a signature hex string, which is assumed to be in the VRS format. + */ +export function parseSignatureHexAsVRS(signatureHex: string): ECSignature { const signatureBuffer = ethUtil.toBuffer(signatureHex); let v = signatureBuffer[0]; // HACK: Sometimes v is returned as [0, 1] and sometimes as [27, 28] @@ -568,4 +341,35 @@ function parseSignatureHexAsRSV(signatureHex: string): ECSignature { }; return ecSignature; } + +/** + * Checks if the supplied elliptic curve signature corresponds to signing `data` with + * the private key corresponding to `signerAddress` + * @param data The hex encoded data signed by the supplied signature. + * @param signature An object containing the elliptic curve signature parameters. + * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. + * @return Whether the ECSignature is valid. + */ +export function isValidECSignature(data: string, signature: ECSignature, signerAddress: string): boolean { + assert.isHexString('data', data); + assert.doesConformToSchema('signature', signature, schemas.ecSignatureSchema); + assert.isETHAddressHex('signerAddress', signerAddress); + const normalizedSignerAddress = signerAddress.toLowerCase(); + + const msgHashBuff = ethUtil.toBuffer(data); + try { + const pubKey = ethUtil.ecrecover( + msgHashBuff, + signature.v, + ethUtil.toBuffer(signature.r), + ethUtil.toBuffer(signature.s), + ); + const retrievedAddress = ethUtil.bufferToHex(ethUtil.pubToAddress(pubKey)); + const normalizedRetrievedAddress = retrievedAddress.toLowerCase(); + return normalizedRetrievedAddress === normalizedSignerAddress; + } catch (err) { + return false; + } +} + // tslint:disable:max-file-line-count diff --git a/packages/order-utils/test/signature_utils_test.ts b/packages/order-utils/test/signature_utils_test.ts index 578aae1e02..bd74eb89c9 100644 --- a/packages/order-utils/test/signature_utils_test.ts +++ b/packages/order-utils/test/signature_utils_test.ts @@ -1,4 +1,5 @@ import { assert } from '@0x/assert'; +import { DevUtilsContract } from '@0x/contracts-dev-utils'; import { Order, SignatureType, ZeroExTransaction } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; @@ -7,9 +8,9 @@ import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; import 'mocha'; -import { generatePseudoRandomSalt, orderHashUtils, transactionHashUtils } from '../src'; +import { generatePseudoRandomSalt } from '../src'; import { constants } from '../src/constants'; -import { signatureUtils } from '../src/signature_utils'; +import { isValidECSignature, signatureUtils } from '../src/signature_utils'; import { chaiSetup } from './utils/chai_setup'; import { provider, web3Wrapper } from './utils/web3_wrapper'; @@ -17,6 +18,10 @@ import { provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; +const devUtilsContract = new DevUtilsContract('0x0000000000000000000000000000000000000000', { + isEIP1193: true, +} as any); + describe('Signature utils', () => { let makerAddress: string; const fakeExchangeContractAddress = '0x1dc4c1cefef38a777b15aa20260a54e584b16c48'; @@ -56,78 +61,6 @@ describe('Signature utils', () => { gasPrice: new BigNumber(0), }; }); - describe('#isValidSignatureAsync', () => { - let dataHex = '0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b0'; - const ethSignSignature = - '0x1B61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace225403'; - let address = '0x5409ed021d9299bf6814279a6a1411a7e866a631'; - - it("should return false if the data doesn't pertain to the signature & address", async () => { - const bytes32Zeros = '0x0000000000000000000000000000000000000000000000000000000000000000'; - expect( - await signatureUtils.isValidSignatureAsync(provider, bytes32Zeros, ethSignSignature, address), - ).to.be.false(); - }); - it("should return false if the address doesn't pertain to the signature & data", async () => { - const validUnrelatedAddress = '0x8b0292b11a196601ed2ce54b665cafeca0347d42'; - expect( - await signatureUtils.isValidSignatureAsync(provider, dataHex, ethSignSignature, validUnrelatedAddress), - ).to.be.false(); - }); - it("should return false if the signature doesn't pertain to the dataHex & address", async () => { - const signatureArray = ethSignSignature.split(''); - // tslint:disable-next-line:custom-no-magic-numbers - signatureArray[5] = 'C'; // V = 28, instead of 27 - const wrongSignature = signatureArray.join(''); - expect( - await signatureUtils.isValidSignatureAsync(provider, dataHex, wrongSignature, address), - ).to.be.false(); - }); - - it('should throw if signatureType is invalid', () => { - const signatureArray = ethSignSignature.split(''); - signatureArray[3] = '9'; // SignatureType w/ index 9 doesn't exist - const signatureWithInvalidType = signatureArray.join(''); - expect( - signatureUtils.isValidSignatureAsync(provider, dataHex, signatureWithInvalidType, address), - ).to.be.rejected(); - }); - - it('should return true for a valid Ecrecover (EthSign) signature', async () => { - const isValidSignatureLocal = await signatureUtils.isValidSignatureAsync( - provider, - dataHex, - ethSignSignature, - address, - ); - expect(isValidSignatureLocal).to.be.true(); - }); - - it('should return true for a valid EIP712 signature', async () => { - dataHex = '0xa1d7403bcbbcd75ec233cfd6584ff8dabed677d0e9bb32c2bea94e9dd8a109da'; - address = '0x6ecbe1db9ef729cbe972c83fb886247691fb6beb'; - const eip712Signature = - '0x1bdde07aac4bf12c12ddbb155919c43eba4146a2cfcf904a862950dbebe332554c6674975603eb5a4eaf8fd7f2e06350267e5b36cda9851a89f8bb49fe2fc9afe202'; - const isValidSignatureLocal = await signatureUtils.isValidSignatureAsync( - provider, - dataHex, - eip712Signature, - address, - ); - expect(isValidSignatureLocal).to.be.true(); - }); - - it('should return false if entry not found in `preSigned` mapping', async () => { - const preSignedSignature = '0x06'; - const isValidPreSignature = await signatureUtils.isValidSignatureAsync( - provider, - dataHex, - preSignedSignature, - address, - ); - expect(isValidPreSignature).to.be.false(); - }); - }); describe('#isValidECSignature', () => { const signature = { v: 27, @@ -138,18 +71,18 @@ describe('Signature utils', () => { const address = '0x0e5cb767cce09a7f3ca594df118aa519be5e2b5a'; it("should return false if the data doesn't pertain to the signature & address", async () => { - expect(signatureUtils.isValidECSignature('0x0', signature, address)).to.be.false(); + expect(isValidECSignature('0x0', signature, address)).to.be.false(); }); it("should return false if the address doesn't pertain to the signature & data", async () => { const validUnrelatedAddress = '0x8b0292b11a196601ed2ce54b665cafeca0347d42'; - expect(signatureUtils.isValidECSignature(data, signature, validUnrelatedAddress)).to.be.false(); + expect(isValidECSignature(data, signature, validUnrelatedAddress)).to.be.false(); }); it("should return false if the signature doesn't pertain to the data & address", async () => { const wrongSignature = _.assign({}, signature, { v: 28 }); - expect(signatureUtils.isValidECSignature(data, wrongSignature, address)).to.be.false(); + expect(isValidECSignature(data, wrongSignature, address)).to.be.false(); }); it('should return true if the signature does pertain to the data & address', async () => { - const isValidSignatureLocal = signatureUtils.isValidECSignature(data, signature, address); + const isValidSignatureLocal = isValidECSignature(data, signature, address); expect(isValidSignatureLocal).to.be.true(); }); }); @@ -342,23 +275,21 @@ describe('Signature utils', () => { expect(ecSignature).to.equal(expectedSignature); }); it('should return a valid signature', async () => { + const expectedSignature = + '0x1b117902c86dfb95fe0d1badd983ee166ad259b27acb220174cbb4460d872871137feabdfe76e05924b484789f79af4ee7fa29ec006cedce1bbf369320d034e10b03'; + const orderHash = '0x34decbedc118904df65f379a175bb39ca18209d6ce41d5ed549d54e6e0a95004'; const ecSignature = await signatureUtils.ecSignHashAsync(provider, orderHash, makerAddress); - - const isValidSignature = await signatureUtils.isValidSignatureAsync( - provider, - orderHash, - ecSignature, - makerAddress, - ); - expect(isValidSignature).to.be.true(); + expect(ecSignature).to.equal(expectedSignature); }); }); describe('#ecSignTypedDataOrderAsync', () => { it('should result in the same signature as signing the order hash without an ethereum message prefix', async () => { // Note: Since order hash is an EIP712 hash the result of a valid EIP712 signature // of order hash is the same as signing the order without the Ethereum Message prefix. - const orderHashHex = orderHashUtils.getOrderHashHex(order); + const orderHashHex = await devUtilsContract + .getOrderHash(order, new BigNumber(order.chainId), order.exchangeAddress) + .callAsync(); const sig = ethUtil.ecsign( ethUtil.toBuffer(orderHashHex), Buffer.from('F2F48EE19680706196E2E339E5DA3491186E0C4C5030670656B0E0164837257D', 'hex'), @@ -371,14 +302,7 @@ describe('Signature utils', () => { ]); const signatureHex = `0x${signatureBuffer.toString('hex')}`; const signedOrder = await signatureUtils.ecSignTypedDataOrderAsync(provider, order, makerAddress); - const isValidSignature = await signatureUtils.isValidSignatureAsync( - provider, - orderHashHex, - signedOrder.signature, - makerAddress, - ); expect(signatureHex).to.eq(signedOrder.signature); - expect(isValidSignature).to.eq(true); }); it('should return the correct signature for signatureHex concatenated as R + S + V', async () => { const expectedSignature = @@ -406,7 +330,13 @@ describe('Signature utils', () => { it('should result in the same signature as signing the order hash without an ethereum message prefix', async () => { // Note: Since order hash is an EIP712 hash the result of a valid EIP712 signature // of order hash is the same as signing the order without the Ethereum Message prefix. - const transactionHashHex = transactionHashUtils.getTransactionHashHex(transaction); + const transactionHashHex = await devUtilsContract + .getTransactionHash( + transaction, + new BigNumber(transaction.domain.chainId), + transaction.domain.verifyingContract, + ) + .callAsync(); const sig = ethUtil.ecsign( ethUtil.toBuffer(transactionHashHex), Buffer.from('F2F48EE19680706196E2E339E5DA3491186E0C4C5030670656B0E0164837257D', 'hex'), @@ -423,14 +353,7 @@ describe('Signature utils', () => { transaction, makerAddress, ); - const isValidSignature = await signatureUtils.isValidSignatureAsync( - provider, - transactionHashHex, - signedTransaction.signature, - makerAddress, - ); expect(signatureHex).to.eq(signedTransaction.signature); - expect(isValidSignature).to.eq(true); }); it('should return the correct Signature for signatureHex concatenated as R + S + V', async () => { const fakeProvider = { diff --git a/packages/orderbook/CHANGELOG.json b/packages/orderbook/CHANGELOG.json index 343345e6c0..5312ffda33 100644 --- a/packages/orderbook/CHANGELOG.json +++ b/packages/orderbook/CHANGELOG.json @@ -2,6 +2,10 @@ { "version": "0.1.0-beta.2", "changes": [ + { + "note": "Added dependency on @0x/contracts-dev-utils", + "pr": 2321 + }, { "note": "Update Mesh RPC logic to v6.0.1-beta", "pr": 2325 diff --git a/packages/orderbook/package.json b/packages/orderbook/package.json index 0ccdb90d6b..cfe5bd61ce 100644 --- a/packages/orderbook/package.json +++ b/packages/orderbook/package.json @@ -44,6 +44,7 @@ "dependencies": { "@0x/assert": "^2.2.0-beta.1", "@0x/connect": "^5.1.0-beta.1", + "@0x/contracts-dev-utils": "^0.1.0-beta.1", "@0x/mesh-rpc-client": "^6.0.1-beta", "@0x/order-utils": "^8.5.0-beta.1", "@0x/utils": "^4.6.0-beta.1" diff --git a/packages/orderbook/src/order_provider/base_order_provider.ts b/packages/orderbook/src/order_provider/base_order_provider.ts index 31a3770894..e831d0fd05 100644 --- a/packages/orderbook/src/order_provider/base_order_provider.ts +++ b/packages/orderbook/src/order_provider/base_order_provider.ts @@ -26,9 +26,9 @@ export abstract class BaseOrderProvider { public abstract async addOrdersAsync(orders: SignedOrder[]): Promise; - protected _updateStore(addedRemoved: AddedRemovedOrders): void { + protected async _updateStoreAsync(addedRemoved: AddedRemovedOrders): Promise { const orderSet = this._orderStore.getOrderSetForAssetPair(addedRemoved.assetPairKey); - orderSet.addMany(addedRemoved.added); - orderSet.deleteMany(addedRemoved.removed); + await orderSet.addManyAsync(addedRemoved.added); + await orderSet.deleteManyAsync(addedRemoved.removed); } } diff --git a/packages/orderbook/src/order_provider/custom_order_provider.ts b/packages/orderbook/src/order_provider/custom_order_provider.ts index db87ed64bd..f47e608f96 100644 --- a/packages/orderbook/src/order_provider/custom_order_provider.ts +++ b/packages/orderbook/src/order_provider/custom_order_provider.ts @@ -41,11 +41,11 @@ export class CustomOrderProvider extends BaseOrderProvider { public async addOrdersAsync(orders: SignedOrder[]): Promise { for (const order of orders) { const orderSet = this._orderStore.getOrderSetForAssets(order.makerAssetData, order.takerAssetData); - orderSet.add({ + await orderSet.addAsync({ order, metaData: { remainingFillableTakerAssetAmount: order.takerAssetAmount, - orderHash: utils.getOrderHash(order), + orderHash: await utils.getOrderHashAsync(order), }, }); } diff --git a/packages/orderbook/src/order_provider/mesh_order_provider.ts b/packages/orderbook/src/order_provider/mesh_order_provider.ts index e7890645df..e3892b40de 100644 --- a/packages/orderbook/src/order_provider/mesh_order_provider.ts +++ b/packages/orderbook/src/order_provider/mesh_order_provider.ts @@ -113,7 +113,7 @@ export class MeshOrderProvider extends BaseOrderProvider { if (this._wsSubscriptionId) { return; } - this._wsSubscriptionId = await this._wsClient.subscribeToOrdersAsync(this._handleOrderUpdates.bind(this)); + this._wsSubscriptionId = await this._wsClient.subscribeToOrdersAsync(this._handleOrderUpdatesAsync.bind(this)); await this._fetchOrdersAndStoreAsync(); // On Reconnnect sync all of the orders currently stored this._wsClient.onReconnected(() => { @@ -133,7 +133,7 @@ export class MeshOrderProvider extends BaseOrderProvider { this._wsClient.addOrdersAsync(Array.from(currentOrders.values()).map(o => o.order)), ); // Remove any rejected orders - this._updateStore({ + await this._updateStoreAsync({ assetPairKey, added: [], removed: rejected.map(o => MeshOrderProvider._orderInfoToAPIOrder(o)), @@ -159,7 +159,7 @@ export class MeshOrderProvider extends BaseOrderProvider { ordersByAssetPairKey[assetPairKey].push(MeshOrderProvider._orderInfoToAPIOrder(order)); } for (const assetPairKey of Object.keys(ordersByAssetPairKey)) { - this._updateStore({ + await this._updateStoreAsync({ added: ordersByAssetPairKey[assetPairKey], removed: [], assetPairKey, @@ -171,7 +171,7 @@ export class MeshOrderProvider extends BaseOrderProvider { * Handles the order events converting to APIOrders and either adding or removing based on its kind. * @param orderEvents The set of `OrderEvents` returned from a mesh subscription update */ - private _handleOrderUpdates(orderEvents: OrderEvent[]): void { + private async _handleOrderUpdatesAsync(orderEvents: OrderEvent[]): Promise { const addedRemovedByAssetPairKey: { [assetPairKey: string]: AddedRemovedOrders } = {}; for (const event of orderEvents) { const { makerAssetData, takerAssetData } = event.signedOrder; @@ -204,7 +204,7 @@ export class MeshOrderProvider extends BaseOrderProvider { } } for (const assetPairKey of Object.keys(addedRemovedByAssetPairKey)) { - this._updateStore(addedRemovedByAssetPairKey[assetPairKey]); + await this._updateStoreAsync(addedRemovedByAssetPairKey[assetPairKey]); } } } diff --git a/packages/orderbook/src/order_provider/sra_polling_order_provider.ts b/packages/orderbook/src/order_provider/sra_polling_order_provider.ts index a3f6ab2f57..33a56fb80b 100644 --- a/packages/orderbook/src/order_provider/sra_polling_order_provider.ts +++ b/packages/orderbook/src/order_provider/sra_polling_order_provider.ts @@ -56,7 +56,7 @@ export class SRAPollingOrderProvider extends BaseSRAOrderProvider { // first time we have had this request, preload the local storage const orders = await this._fetchLatestOrdersAsync(makerAssetData, takerAssetData); // Set the OrderSet for the polling to diff against - this._updateStore({ added: orders, removed: [], assetPairKey }); + await this._updateStoreAsync({ added: orders, removed: [], assetPairKey }); // Create a HTTP polling subscription const pollingIntervalId = (this._createPollingSubscription(makerAssetData, takerAssetData) as any) as number; this._assetPairKeyToPollingIntervalId.set(assetPairKey, pollingIntervalId); @@ -71,8 +71,10 @@ export class SRAPollingOrderProvider extends BaseSRAOrderProvider { async () => { const previousOrderSet = this._orderStore.getOrderSetForAssetPair(assetPairKey); const orders = await this._fetchLatestOrdersAsync(makerAssetData, takerAssetData); - const diff = previousOrderSet.diff(new OrderSet(orders)); - this._updateStore({ ...diff, assetPairKey }); + const orderSet = new OrderSet(); + await orderSet.addManyAsync(orders); + const diff = await previousOrderSet.diffAsync(orderSet); + await this._updateStoreAsync({ ...diff, assetPairKey }); }, this._pollingIntervalMs, (_: Error) => { diff --git a/packages/orderbook/src/order_provider/sra_websocket_order_provider.ts b/packages/orderbook/src/order_provider/sra_websocket_order_provider.ts index f54c855e43..3f127fb356 100644 --- a/packages/orderbook/src/order_provider/sra_websocket_order_provider.ts +++ b/packages/orderbook/src/order_provider/sra_websocket_order_provider.ts @@ -102,9 +102,10 @@ export class SRAWebsocketOrderProvider extends BaseSRAOrderProvider { const orders = await this._fetchLatestOrdersAsync(makerAssetData, takerAssetData); const assetPairKey = OrderStore.getKeyForAssetPair(makerAssetData, takerAssetData); const currentOrders = this._orderStore.getOrderSetForAssetPair(assetPairKey); - const newOrders = new OrderSet(orders); - const diff = currentOrders.diff(newOrders); - this._updateStore({ + const newOrders = new OrderSet(); + await newOrders.addManyAsync(orders); + const diff = await currentOrders.diffAsync(newOrders); + await this._updateStoreAsync({ added: diff.added, removed: diff.removed, assetPairKey, @@ -123,7 +124,7 @@ export class SRAWebsocketOrderProvider extends BaseSRAOrderProvider { */ private async _createOrdersChannelAsync(): Promise { const ordersChannelHandler: OrdersChannelHandler = { - onUpdate: async (_channel, _opts, apiOrders) => this._handleOrderUpdates(apiOrders), + onUpdate: async (_channel, _opts, apiOrders) => this._handleOrderUpdatesAsync(apiOrders), // tslint:disable-next-line:no-empty onError: (_channel, _err) => {}, onClose: async () => { @@ -154,7 +155,7 @@ export class SRAWebsocketOrderProvider extends BaseSRAOrderProvider { * which have remainingFillableTakerAssetAmount as 0. * @param orders the set of API Orders returned from the websocket channel */ - private _handleOrderUpdates(orders: APIOrder[]): void { + private async _handleOrderUpdatesAsync(orders: APIOrder[]): Promise { const addedRemovedByKey: { [assetPairKey: string]: AddedRemovedOrders } = {}; for (const order of orders) { const assetPairKey = OrderStore.getKeyForAssetPair(order.order.makerAssetData, order.order.takerAssetData); @@ -172,7 +173,7 @@ export class SRAWebsocketOrderProvider extends BaseSRAOrderProvider { } for (const assetPairKey of Object.keys(addedRemovedByKey)) { - this._updateStore(addedRemovedByKey[assetPairKey]); + await this._updateStoreAsync(addedRemovedByKey[assetPairKey]); } } } diff --git a/packages/orderbook/src/order_set.ts b/packages/orderbook/src/order_set.ts index 577bd2ffa7..e862e9bbf5 100644 --- a/packages/orderbook/src/order_set.ts +++ b/packages/orderbook/src/order_set.ts @@ -4,45 +4,42 @@ import { utils } from './utils'; export class OrderSet { private readonly _map: Map; - constructor(orders: APIOrder[] = []) { + constructor() { this._map = new Map(); (this as any)[Symbol.iterator] = this.values; - for (const order of orders) { - this.add(order); - } } public size(): number { return this._map.size; } - public add(item: APIOrder): void { - const orderHash = utils.getOrderHash(item); + public async addAsync(item: APIOrder): Promise { + const orderHash = await utils.getOrderHashAsync(item); (item.metaData as any).orderHash = orderHash; this._map.set(orderHash, item); } - public addMany(items: APIOrder[]): void { + public async addManyAsync(items: APIOrder[]): Promise { for (const item of items) { - this.add(item); + await this.addAsync(item); } } - public has(order: APIOrder): boolean { - return this._map.has(utils.getOrderHash(order)); + public async hasAsync(order: APIOrder): Promise { + return this._map.has(await utils.getOrderHashAsync(order)); } - public diff(other: OrderSet): { added: APIOrder[]; removed: APIOrder[] } { + public async diffAsync(other: OrderSet): Promise<{ added: APIOrder[]; removed: APIOrder[] }> { const added: APIOrder[] = []; const removed: APIOrder[] = []; for (const otherItem of other.values()) { - const doesContainItem = this._map.has(utils.getOrderHash(otherItem)); + const doesContainItem = this._map.has(await utils.getOrderHashAsync(otherItem)); if (!doesContainItem) { added.push(otherItem); } } for (const item of this.values()) { - const doesContainItem = other._map.has(utils.getOrderHash(item)); + const doesContainItem = other._map.has(await utils.getOrderHashAsync(item)); if (!doesContainItem) { removed.push(item); } @@ -54,13 +51,13 @@ export class OrderSet { return this._map.values(); } - public delete(item: APIOrder): boolean { - return this._map.delete(utils.getOrderHash(item)); + public async deleteAsync(item: APIOrder): Promise { + return this._map.delete(await utils.getOrderHashAsync(item)); } - public deleteMany(items: APIOrder[]): void { + public async deleteManyAsync(items: APIOrder[]): Promise { for (const item of items) { - this.delete(item); + await this.deleteAsync(item); } } } diff --git a/packages/orderbook/src/order_store.ts b/packages/orderbook/src/order_store.ts index 15e86029f8..16c42e3fab 100644 --- a/packages/orderbook/src/order_store.ts +++ b/packages/orderbook/src/order_store.ts @@ -25,11 +25,11 @@ export class OrderStore { } return orderSet; } - public update(addedRemoved: AddedRemovedOrders): void { + public async updateAsync(addedRemoved: AddedRemovedOrders): Promise { const { added, removed, assetPairKey } = addedRemoved; const orders = this.getOrderSetForAssetPair(assetPairKey); - orders.addMany(added); - orders.deleteMany(removed); + await orders.addManyAsync(added); + await orders.deleteManyAsync(removed); } public has(assetPairKey: string): boolean { return this._orders.has(assetPairKey); diff --git a/packages/orderbook/src/utils.ts b/packages/orderbook/src/utils.ts index f2cc0ba10c..83c89523da 100644 --- a/packages/orderbook/src/utils.ts +++ b/packages/orderbook/src/utils.ts @@ -1,14 +1,26 @@ import { APIOrder, SignedOrder } from '@0x/connect'; -import { orderHashUtils } from '@0x/order-utils'; +import { DevUtilsContract } from '@0x/contracts-dev-utils'; +import { BigNumber } from '@0x/utils'; + +const devUtilsContract = new DevUtilsContract('0x0000000000000000000000000000000000000000', { + isEIP1193: true, +} as any); export const utils = { - getOrderHash: (order: APIOrder | SignedOrder): string => { + async getOrderHashAsync(order: APIOrder | SignedOrder): Promise { if ((order as APIOrder).metaData) { const apiOrder = order as APIOrder; - const orderHash = (apiOrder.metaData as any).orderHash || orderHashUtils.getOrderHashHex(apiOrder.order); + const orderHash = + (apiOrder.metaData as any).orderHash || + (await devUtilsContract + .getOrderHash(apiOrder.order, new BigNumber(apiOrder.order.chainId), apiOrder.order.exchangeAddress) + .callAsync()); return orderHash; } else { - const orderHash = orderHashUtils.getOrderHashHex(order as SignedOrder); + const signedOrder = order as SignedOrder; + const orderHash = await devUtilsContract + .getOrderHash(signedOrder, new BigNumber(signedOrder.chainId), signedOrder.exchangeAddress) + .callAsync(); return orderHash; } }, diff --git a/packages/orderbook/test/utils.test.ts b/packages/orderbook/test/utils.test.ts index 565de836f3..031d3e4db3 100644 --- a/packages/orderbook/test/utils.test.ts +++ b/packages/orderbook/test/utils.test.ts @@ -23,8 +23,8 @@ describe('Utils', () => { '0x1cf16c2f3a210965b5e17f51b57b869ba4ddda33df92b0017b4d8da9dacd3152b122a73844eaf50ccde29a42950239ba36a525ed7f1698a8a5e1896cf7d651aed203', }; test('calculates the orderhash if it does not exist', async () => { - const orderHash = utils.getOrderHash(order as any); - const calculatedOrderHash = utils.getOrderHash({ order: order as any, metaData: {} }); + const orderHash = await utils.getOrderHashAsync(order as any); + const calculatedOrderHash = await utils.getOrderHashAsync({ order: order as any, metaData: {} }); expect(orderHash).toBe(calculatedOrderHash); expect(orderHash).toBe('0x5a0f346c671a39b832a487d2d7eb63ca19301554cf1f8a98a19d478a3a8be32c'); }); diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json index badd6f835f..501498f118 100644 --- a/packages/utils/CHANGELOG.json +++ b/packages/utils/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "4.6.0-beta.2", + "changes": [ + { + "note": "Removed exports AuthorizableRevertErrors, LibAddressArrayRevertErrors, LibBytesRevertErrors, OwnableRevertErrors, ReentrancyGuardRevertErrors and SafeMathRevertErrors", + "pr": 2321 + } + ] + }, { "version": "4.6.0-beta.1", "changes": [ diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 67375e0eaf..9023e9c977 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -1,11 +1,3 @@ -export import AuthorizableRevertErrors = require('./authorizable_revert_errors'); -export import FixedMathRevertErrors = require('./fixed_math_revert_errors'); -export import LibAddressArrayRevertErrors = require('./lib_address_array_revert_errors'); -export import LibBytesRevertErrors = require('./lib_bytes_revert_errors'); -export import OwnableRevertErrors = require('./ownable_revert_errors'); -export import ReentrancyGuardRevertErrors = require('./reentrancy_guard_revert_errors'); -export import SafeMathRevertErrors = require('./safe_math_revert_errors'); - export { promisify } from './promisify'; export { addressUtils } from './address_utils'; export { classUtils } from './class_utils';