diff --git a/contracts/coordinator/src/index.ts b/contracts/coordinator/src/index.ts index 45a575245a..240e303d34 100644 --- a/contracts/coordinator/src/index.ts +++ b/contracts/coordinator/src/index.ts @@ -7,7 +7,7 @@ export { LibCoordinatorRichErrorsContract, LibEIP712CoordinatorDomainContract, } from './wrappers'; -export import CoordinatorRevertErrors = require('./revert_errors'); +export { CoordinatorRevertErrors } from '@0x/utils'; export { CoordinatorServerCancellationResponse } from './client/index'; export { ApprovalFactory } from './approval_factory'; export { SignedCoordinatorApproval } from './types'; diff --git a/contracts/coordinator/src/revert_errors.ts b/contracts/coordinator/src/revert_errors.ts deleted file mode 100644 index 4433790a8e..0000000000 --- a/contracts/coordinator/src/revert_errors.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { BigNumber, RevertError } from '@0x/utils'; - -// tslint:disable:max-classes-per-file - -export enum SignatureErrorCodes { - InvalidLength, - Unsupported, - Illegal, - Invalid, -} - -export class SignatureError extends RevertError { - constructor(errorCode?: SignatureErrorCodes, hash?: string, signature?: string) { - super('SignatureError', 'SignatureError(uint8 errorCode, bytes32 hash, bytes signature)', { - errorCode, - hash, - signature, - }); - } -} - -export class InvalidOriginError extends RevertError { - constructor(expectedOrigin?: string) { - super('InvalidOriginError', 'InvalidOriginError(address expectedOrigin)', { expectedOrigin }); - } -} - -export class ApprovalExpiredError extends RevertError { - constructor(transactionHash?: string, approvalExpirationTime?: BigNumber | number | string) { - super('ApprovalExpiredError', 'ApprovalExpiredError(bytes32 transactionHash, uint256 approvalExpirationTime)', { - transactionHash, - approvalExpirationTime, - }); - } -} - -export class InvalidApprovalSignatureError extends RevertError { - constructor(transactionHash?: string, approverAddress?: string) { - super( - 'InvalidApprovalSignatureError', - 'InvalidApprovalSignatureError(bytes32 transactionHash, address approverAddress)', - { transactionHash, approverAddress }, - ); - } -} - -const types = [SignatureError, InvalidOriginError, ApprovalExpiredError, InvalidApprovalSignatureError]; - -// Register the types we've defined. -for (const type of types) { - RevertError.registerType(type); -} diff --git a/contracts/coordinator/test/mixins.ts b/contracts/coordinator/test/mixins.ts index 57f22a9a4d..e5c2ee42a2 100644 --- a/contracts/coordinator/test/mixins.ts +++ b/contracts/coordinator/test/mixins.ts @@ -12,9 +12,7 @@ import { } from '@0x/contracts-test-utils'; import { LibBytesRevertErrors } from '@0x/contracts-utils'; import { SignatureType, SignedOrder } from '@0x/types'; -import { BigNumber } from '@0x/utils'; - -import CoordinatorRevertErrors = require('../src/revert_errors'); +import { BigNumber, CoordinatorRevertErrors } from '@0x/utils'; import { ApprovalFactory } from '../src/approval_factory'; diff --git a/contracts/exchange-forwarder/src/index.ts b/contracts/exchange-forwarder/src/index.ts index af6bcb28b2..dd06356a44 100644 --- a/contracts/exchange-forwarder/src/index.ts +++ b/contracts/exchange-forwarder/src/index.ts @@ -1,6 +1,6 @@ export { artifacts } from './artifacts'; export { ForwarderContract } from './wrappers'; -export import ForwarderRevertErrors = require('./revert_errors'); +export { ExchangeForwarderRevertErrors } from '@0x/utils'; export { ContractArtifact, ContractChains, diff --git a/contracts/exchange-forwarder/src/revert_errors.ts b/contracts/exchange-forwarder/src/revert_errors.ts deleted file mode 100644 index dfd4071fb1..0000000000 --- a/contracts/exchange-forwarder/src/revert_errors.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { BigNumber, RevertError } from '@0x/utils'; - -// tslint:disable:max-classes-per-file - -export class UnregisteredAssetProxyError extends RevertError { - constructor() { - super('UnregisteredAssetProxyError', 'UnregisteredAssetProxyError()', {}); - } -} - -export class UnsupportedAssetProxyError extends RevertError { - constructor(proxyId?: string) { - super('UnsupportedAssetProxyError', 'UnsupportedAssetProxyError(bytes4 proxyId)', { proxyId }); - } -} - -export class CompleteBuyFailedError extends RevertError { - constructor( - expectedAssetBuyAmount?: BigNumber | number | string, - actualAssetBuyAmount?: BigNumber | number | string, - ) { - super( - 'CompleteBuyFailedError', - 'CompleteBuyFailedError(uint256 expectedAssetBuyAmount, uint256 actualAssetBuyAmount)', - { expectedAssetBuyAmount, actualAssetBuyAmount }, - ); - } -} - -export class UnsupportedFeeError extends RevertError { - constructor(takerFeeAssetData?: string) { - super('UnsupportedFeeError', 'UnsupportedFeeError(bytes takerFeeAssetData)', { takerFeeAssetData }); - } -} - -export class FeePercentageTooLargeError extends RevertError { - constructor(feePercentage?: BigNumber | number | string) { - super('FeePercentageTooLargeError', 'FeePercentageTooLargeError(uint256 feePercentage)', { - feePercentage, - }); - } -} - -export class InsufficientEthForFeeError extends RevertError { - constructor(ethFeeRequired?: BigNumber | number | string, ethAvailable?: BigNumber | number | string) { - super( - 'InsufficientEthForFeeError', - 'InsufficientEthForFeeError(uint256 ethFeeRequired, uint256 ethAvailable)', - { ethFeeRequired, ethAvailable }, - ); - } -} - -export class OverspentWethError extends RevertError { - constructor(wethSpent?: BigNumber | number | string, msgValue?: BigNumber | number | string) { - super('OverspentWethError', 'OverspentWethError(uint256 wethSpent, uint256 msgValue)', { - wethSpent, - msgValue, - }); - } -} - -export class DefaultFunctionWethContractOnlyError extends RevertError { - constructor(senderAddress?: string) { - super('DefaultFunctionWethContractOnlyError', 'DefaultFunctionWethContractOnlyError(address senderAddress)', { - senderAddress, - }); - } -} - -export class MsgValueCannotEqualZeroError extends RevertError { - constructor() { - super('MsgValueCannotEqualZeroError', 'MsgValueCannotEqualZeroError()', {}); - } -} - -export class Erc721AmountMustEqualOneError extends RevertError { - constructor(amount?: BigNumber | number | string) { - super('Erc721AmountMustEqualOneError', 'Erc721AmountMustEqualOneError(uint256 amount)', { - amount, - }); - } -} - -const types = [ - UnregisteredAssetProxyError, - UnsupportedAssetProxyError, - CompleteBuyFailedError, - UnsupportedFeeError, - FeePercentageTooLargeError, - InsufficientEthForFeeError, - OverspentWethError, - DefaultFunctionWethContractOnlyError, - MsgValueCannotEqualZeroError, - Erc721AmountMustEqualOneError, -]; - -// Register the types we've defined. -for (const type of types) { - RevertError.registerType(type); -} diff --git a/contracts/exchange-forwarder/test/asset_test.ts b/contracts/exchange-forwarder/test/asset_test.ts index 77fa1c8c3e..fab1391d59 100644 --- a/contracts/exchange-forwarder/test/asset_test.ts +++ b/contracts/exchange-forwarder/test/asset_test.ts @@ -21,9 +21,7 @@ import { randomAddress, verifyEventsFromLogs, } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; - -import { ForwarderRevertErrors } from '../src'; +import { BigNumber, ExchangeForwarderRevertErrors } from '@0x/utils'; import { artifacts } from './artifacts'; import { TestForwarderContract } from './wrappers'; @@ -159,7 +157,7 @@ blockchainTests('Supported asset type unit tests', env => { const tx = forwarder .transferAssetToSender(erc721AssetData, invalidAmount) .awaitTransactionSuccessAsync({ from: receiver }); - const expectedError = new ForwarderRevertErrors.Erc721AmountMustEqualOneError(invalidAmount); + const expectedError = new ExchangeForwarderRevertErrors.Erc721AmountMustEqualOneError(invalidAmount); return expect(tx).to.revertWith(expectedError); }); it('transfers an ERC20 token given ERC20Bridge assetData', async () => { @@ -177,7 +175,9 @@ blockchainTests('Supported asset type unit tests', env => { const tx = forwarder .transferAssetToSender(randomBytes, TRANSFER_AMOUNT) .awaitTransactionSuccessAsync({ from: receiver }); - const expectedError = new ForwarderRevertErrors.UnsupportedAssetProxyError(hexSlice(randomBytes, 0, 4)); + const expectedError = new ExchangeForwarderRevertErrors.UnsupportedAssetProxyError( + hexSlice(randomBytes, 0, 4), + ); return expect(tx).to.revertWith(expectedError); }); }); diff --git a/contracts/exchange-libs/src/index.ts b/contracts/exchange-libs/src/index.ts index 029a1c093e..f0fb0f8085 100644 --- a/contracts/exchange-libs/src/index.ts +++ b/contracts/exchange-libs/src/index.ts @@ -8,7 +8,7 @@ export { LibOrderContract, LibZeroExTransactionContract, } from './wrappers'; -export import LibMathRevertErrors = require('./lib_math_revert_errors'); +export { LibMathRevertErrors } from '@0x/utils'; import * as ReferenceFunctionsToExport from './reference_functions'; export import ReferenceFunctions = ReferenceFunctionsToExport; diff --git a/contracts/exchange-libs/src/lib_math_revert_errors.ts b/contracts/exchange-libs/src/lib_math_revert_errors.ts deleted file mode 100644 index bf132852d5..0000000000 --- a/contracts/exchange-libs/src/lib_math_revert_errors.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { BigNumber, RevertError } from '@0x/utils'; -import * as _ from 'lodash'; - -// tslint:disable:max-classes-per-file - -export class DivisionByZeroError extends RevertError { - constructor() { - super('DivisionByZeroError', 'DivisionByZeroError()', {}); - } -} - -export class RoundingError extends RevertError { - constructor( - numerator?: BigNumber | number | string, - denominator?: BigNumber | number | string, - target?: BigNumber | number | string, - ) { - super('RoundingError', 'RoundingError(uint256 numerator, uint256 denominator, uint256 target)', { - numerator, - denominator, - target, - }); - } -} - -const types = [DivisionByZeroError, RoundingError]; - -// Register the types we've defined. -for (const type of types) { - RevertError.registerType(type); -} diff --git a/contracts/exchange-libs/src/reference_functions.ts b/contracts/exchange-libs/src/reference_functions.ts index e3ebdf921d..fa57f09b70 100644 --- a/contracts/exchange-libs/src/reference_functions.ts +++ b/contracts/exchange-libs/src/reference_functions.ts @@ -1,8 +1,6 @@ import { ReferenceFunctions } from '@0x/contracts-utils'; import { FillResults, Order } from '@0x/types'; -import { BigNumber } from '@0x/utils'; - -import LibMathRevertErrors = require('./lib_math_revert_errors'); +import { BigNumber, LibMathRevertErrors } from '@0x/utils'; 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 694d2e3e5e..2d8d54ea41 100644 --- a/contracts/exchange-libs/test/lib_fill_results.ts +++ b/contracts/exchange-libs/test/lib_fill_results.ts @@ -9,11 +9,10 @@ import { } from '@0x/contracts-test-utils'; import { SafeMathRevertErrors } from '@0x/contracts-utils'; import { FillResults, MatchedFillResults, Order } from '@0x/types'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, LibMathRevertErrors } 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 30f0441370..4575f200ff 100644 --- a/contracts/exchange-libs/test/lib_math.ts +++ b/contracts/exchange-libs/test/lib_math.ts @@ -7,9 +7,8 @@ import { uint256Values, } from '@0x/contracts-test-utils'; import { SafeMathRevertErrors } from '@0x/contracts-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, LibMathRevertErrors } from '@0x/utils'; -import LibMathRevertErrors = require('../src/lib_math_revert_errors'); import { getPartialAmountCeil, getPartialAmountFloor, diff --git a/contracts/exchange-libs/test/reference_functions.ts b/contracts/exchange-libs/test/reference_functions.ts index 797cace298..08fdf9b7ac 100644 --- a/contracts/exchange-libs/test/reference_functions.ts +++ b/contracts/exchange-libs/test/reference_functions.ts @@ -1,9 +1,8 @@ import { constants, describe, expect } from '@0x/contracts-test-utils'; import { SafeMathRevertErrors } from '@0x/contracts-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, LibMathRevertErrors } from '@0x/utils'; import * as _ from 'lodash'; -import LibMathRevertErrors = require('../src/lib_math_revert_errors'); import { addFillResults, getPartialAmountCeil, diff --git a/contracts/exchange/src/index.ts b/contracts/exchange/src/index.ts index 11d0e6753a..8bce846c1a 100644 --- a/contracts/exchange/src/index.ts +++ b/contracts/exchange/src/index.ts @@ -15,7 +15,7 @@ export { ExchangeProtocolFeeMultiplierEventArgs, ExchangeTransactionExecutionEventArgs, } from './wrappers'; -export import ExchangeRevertErrors = require('./revert_errors'); +export { ExchangeRevertErrors } from '@0x/utils'; export { exchangeDataEncoder } from './exchange_data_encoder'; export { SignedOrder } from '@0x/types'; export { ExchangeFunctionName } from '@0x/contracts-test-utils'; diff --git a/contracts/exchange/src/revert_errors.ts b/contracts/exchange/src/revert_errors.ts deleted file mode 100644 index d5118ffbb4..0000000000 --- a/contracts/exchange/src/revert_errors.ts +++ /dev/null @@ -1,287 +0,0 @@ -import { OrderStatus } from '@0x/types'; -import { BigNumber, RevertError } from '@0x/utils'; -import * as _ from 'lodash'; - -// tslint:disable:max-classes-per-file - -export enum BatchMatchOrdersErrorCodes { - ZeroLeftOrders, - ZeroRightOrders, - InvalidLengthLeftSignatures, - InvalidLengthRightSignatures, -} - -export enum ExchangeContextErrorCodes { - InvalidMaker, - InvalidTaker, - InvalidSender, -} - -export enum FillErrorCode { - InvalidTakerAmount, - TakerOverpay, - Overfill, - InvalidFillPrice, -} - -export enum SignatureErrorCode { - BadOrderSignature, - BadTransactionSignature, - InvalidLength, - Unsupported, - Illegal, - InappropriateSignatureType, - InvalidSigner, -} - -export enum AssetProxyDispatchErrorCode { - InvalidAssetDataLength, - UnknownAssetProxy, -} - -export enum TransactionErrorCode { - AlreadyExecuted, - Expired, -} - -export enum IncompleteFillErrorCode { - IncompleteMarketBuyOrders, - IncompleteMarketSellOrders, - IncompleteFillOrder, -} - -export class BatchMatchOrdersError extends RevertError { - constructor(error?: BatchMatchOrdersErrorCodes) { - super('BatchMatchOrdersError', 'BatchMatchOrdersError(uint8 error)', { error }); - } -} - -export class SignatureError extends RevertError { - constructor(error?: SignatureErrorCode, hash?: string, signer?: string, signature?: string) { - super('SignatureError', 'SignatureError(uint8 error, bytes32 hash, address signer, bytes signature)', { - error, - hash, - signer, - signature, - }); - } -} - -export class SignatureValidatorNotApprovedError extends RevertError { - constructor(signer?: string, validator?: string) { - super( - 'SignatureValidatorNotApprovedError', - 'SignatureValidatorNotApprovedError(address signer, address validator)', - { - signer, - validator, - }, - ); - } -} - -export class SignatureWalletError extends RevertError { - constructor(hash?: string, wallet?: string, signature?: string, errorData?: string) { - super( - 'SignatureWalletError', - 'SignatureWalletError(bytes32 hash, address wallet, bytes signature, bytes errorData)', - { - hash, - wallet, - signature, - errorData, - }, - ); - } -} - -export class EIP1271SignatureError extends RevertError { - constructor(verifyingContract?: string, data?: string, signature?: string, errorData?: string) { - super( - 'EIP1271SignatureError', - 'EIP1271SignatureError(address verifyingContract, bytes data, bytes signature, bytes errorData)', - { - verifyingContract, - data, - signature, - errorData, - }, - ); - } -} - -export class OrderStatusError extends RevertError { - constructor(orderHash?: string, status?: OrderStatus) { - super('OrderStatusError', 'OrderStatusError(bytes32 orderHash, uint8 status)', { orderHash, status }); - } -} - -export class FillError extends RevertError { - constructor(error?: FillErrorCode, orderHash?: string) { - super('FillError', 'FillError(uint8 error, bytes32 orderHash)', { error, orderHash }); - } -} - -export class OrderEpochError extends RevertError { - constructor(maker?: string, sender?: string, currentEpoch?: BigNumber) { - super('OrderEpochError', 'OrderEpochError(address maker, address sender, uint256 currentEpoch)', { - maker, - sender, - currentEpoch, - }); - } -} - -export class AssetProxyExistsError extends RevertError { - constructor(assetProxyId?: string, assetProxy?: string) { - super('AssetProxyExistsError', 'AssetProxyExistsError(bytes4 assetProxyId, address assetProxy)', { - assetProxyId, - assetProxy, - }); - } -} - -export class AssetProxyDispatchError extends RevertError { - constructor(error?: AssetProxyDispatchErrorCode, orderHash?: string, assetData?: string) { - super('AssetProxyDispatchError', 'AssetProxyDispatchError(uint8 error, bytes32 orderHash, bytes assetData)', { - error, - orderHash, - assetData, - }); - } -} - -export class AssetProxyTransferError extends RevertError { - constructor(orderHash?: string, assetData?: string, errorData?: string) { - super( - 'AssetProxyTransferError', - 'AssetProxyTransferError(bytes32 orderHash, bytes assetData, bytes errorData)', - { - orderHash, - assetData, - errorData, - }, - ); - } -} - -export class NegativeSpreadError extends RevertError { - constructor(leftOrderHash?: string, rightOrderHash?: string) { - super('NegativeSpreadError', 'NegativeSpreadError(bytes32 leftOrderHash, bytes32 rightOrderHash)', { - leftOrderHash, - rightOrderHash, - }); - } -} - -export class TransactionError extends RevertError { - constructor(error?: TransactionErrorCode, transactionHash?: string) { - super('TransactionError', 'TransactionError(uint8 error, bytes32 transactionHash)', { error, transactionHash }); - } -} - -export class TransactionExecutionError extends RevertError { - constructor(transactionHash?: string, errorData?: string) { - super('TransactionExecutionError', 'TransactionExecutionError(bytes32 transactionHash, bytes errorData)', { - transactionHash, - errorData, - }); - } -} - -export class TransactionGasPriceError extends RevertError { - constructor(transactionHash?: string, actualGasPrice?: BigNumber, requiredGasPrice?: BigNumber) { - super( - 'TransactionGasPriceError', - 'TransactionGasPriceError(bytes32 transactionHash, uint256 actualGasPrice, uint256 requiredGasPrice)', - { - transactionHash, - actualGasPrice, - requiredGasPrice, - }, - ); - } -} - -export class TransactionInvalidContextError extends RevertError { - constructor(transactionHash?: string, currentContextAddress?: string) { - super( - 'TransactionInvalidContextError', - 'TransactionInvalidContextError(bytes32 transactionHash, address currentContextAddress)', - { - transactionHash, - currentContextAddress, - }, - ); - } -} - -export class IncompleteFillError extends RevertError { - constructor( - error?: IncompleteFillErrorCode, - expectedAssetFillAmount?: BigNumber, - actualAssetFillAmount?: BigNumber, - ) { - super( - 'IncompleteFillError', - 'IncompleteFillError(uint8 error, uint256 expectedAssetFillAmount, uint256 actualAssetFillAmount)', - { - error, - expectedAssetFillAmount, - actualAssetFillAmount, - }, - ); - } -} - -export class ExchangeInvalidContextError extends RevertError { - constructor(error?: ExchangeContextErrorCodes, orderHash?: string, contextAddress?: string) { - super( - 'ExchangeInvalidContextError', - 'ExchangeInvalidContextError(uint8 error, bytes32 orderHash, address contextAddress)', - { error, orderHash, contextAddress }, - ); - } -} -export class PayProtocolFeeError extends RevertError { - constructor( - orderHash?: string, - protocolFee?: BigNumber, - makerAddress?: string, - takerAddress?: string, - errorData?: string, - ) { - super( - 'PayProtocolFeeError', - 'PayProtocolFeeError(bytes32 orderHash, uint256 protocolFee, address makerAddress, address takerAddress, bytes errorData)', - { orderHash, protocolFee, makerAddress, takerAddress, errorData }, - ); - } -} - -const types = [ - AssetProxyExistsError, - AssetProxyDispatchError, - AssetProxyTransferError, - BatchMatchOrdersError, - EIP1271SignatureError, - ExchangeInvalidContextError, - FillError, - IncompleteFillError, - NegativeSpreadError, - OrderEpochError, - OrderStatusError, - PayProtocolFeeError, - SignatureError, - SignatureValidatorNotApprovedError, - SignatureWalletError, - TransactionError, - TransactionExecutionError, - TransactionGasPriceError, - TransactionInvalidContextError, -]; - -// Register the types we've defined. -for (const type of types) { - RevertError.registerType(type); -} diff --git a/contracts/exchange/test/dispatcher.ts b/contracts/exchange/test/dispatcher.ts index 9bbcb4fed1..f9e59e5b19 100644 --- a/contracts/exchange/test/dispatcher.ts +++ b/contracts/exchange/test/dispatcher.ts @@ -19,17 +19,14 @@ import { import { OwnableRevertErrors } from '@0x/contracts-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { AssetProxyId, RevertReason } from '@0x/types'; -import { BigNumber, StringRevertError } from '@0x/utils'; +import { BigNumber, ExchangeRevertErrors, 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'; - import { dependencyArtifacts } from './utils/dependency_artifacts'; +import { TestAssetProxyDispatcherAssetProxyRegisteredEventArgs, TestAssetProxyDispatcherContract } from './wrappers'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/exchange/test/internal.ts b/contracts/exchange/test/internal.ts index 6968bc05d4..eb8a2425ff 100644 --- a/contracts/exchange/test/internal.ts +++ b/contracts/exchange/test/internal.ts @@ -2,20 +2,17 @@ import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-excha import { blockchainTests, constants, expect, hexRandom, orderHashUtils } from '@0x/contracts-test-utils'; import { SafeMathRevertErrors } from '@0x/contracts-utils'; import { Order } from '@0x/types'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, ExchangeRevertErrors } 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, TestExchangeInternalsDispatchTransferFromCalledEventArgs, TestExchangeInternalsFillEventArgs, } from './wrappers'; - blockchainTests('Exchange core internal functions', env => { const CHAIN_ID = 1337; const ONE_ETHER = constants.ONE_ETHER; diff --git a/contracts/exchange/test/isolated_fill_order.ts b/contracts/exchange/test/isolated_fill_order.ts index 057d3d090f..7f552f0818 100644 --- a/contracts/exchange/test/isolated_fill_order.ts +++ b/contracts/exchange/test/isolated_fill_order.ts @@ -2,11 +2,9 @@ import { LibMathRevertErrors, ReferenceFunctions as LibReferenceFunctions } from import { blockchainTests, constants, expect, hexRandom } from '@0x/contracts-test-utils'; import { SafeMathRevertErrors } from '@0x/contracts-utils'; import { FillResults, OrderInfo, OrderStatus, SignatureType } from '@0x/types'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, ExchangeRevertErrors } 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 b1ad617424..9136f13dfd 100644 --- a/contracts/exchange/test/lib_exchange_rich_error_decoder.ts +++ b/contracts/exchange/test/lib_exchange_rich_error_decoder.ts @@ -8,11 +8,9 @@ import { randomAddress, } from '@0x/contracts-test-utils'; import { generatePseudoRandomSalt } from '@0x/order-utils'; -import { BigNumber, RevertError } from '@0x/utils'; +import { BigNumber, ExchangeRevertErrors, 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/signature_validator.ts b/contracts/exchange/test/signature_validator.ts index cbf5a79efd..fea72881a5 100644 --- a/contracts/exchange/test/signature_validator.ts +++ b/contracts/exchange/test/signature_validator.ts @@ -16,12 +16,10 @@ import { transactionHashUtils, } from '@0x/contracts-test-utils'; import { SignatureType, SignedOrder, SignedZeroExTransaction } from '@0x/types'; -import { BigNumber, StringRevertError } from '@0x/utils'; +import { BigNumber, ExchangeRevertErrors, 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 { ExchangeContract, diff --git a/contracts/exchange/test/transactions.ts b/contracts/exchange/test/transactions.ts index 13d632ab4c..584fa60eb0 100644 --- a/contracts/exchange/test/transactions.ts +++ b/contracts/exchange/test/transactions.ts @@ -15,13 +15,12 @@ import { transactionHashUtils, } from '@0x/contracts-test-utils'; import { FillResults, OrderStatus } from '@0x/types'; -import { AbiEncoder, BigNumber } from '@0x/utils'; +import { AbiEncoder, BigNumber, ExchangeRevertErrors } from '@0x/utils'; import { LogWithDecodedArgs, MethodAbi } from 'ethereum-types'; 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 87f1925256..f84160f422 100644 --- a/contracts/exchange/test/transactions_unit_tests.ts +++ b/contracts/exchange/test/transactions_unit_tests.ts @@ -7,12 +7,10 @@ import { transactionHashUtils, } from '@0x/contracts-test-utils'; import { EIP712DomainWithDefaultSchema, ZeroExTransaction } from '@0x/types'; -import { BigNumber, StringRevertError } from '@0x/utils'; +import { BigNumber, ExchangeRevertErrors, 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 9a08ae78fb..4089d1acf0 100644 --- a/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts +++ b/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts @@ -14,7 +14,7 @@ import { LogWithDecodedArgs, TxData } from 'ethereum-types'; import * as _ from 'lodash'; import 'make-promises-safe'; -import ExchangeRevertErrors = require('../../src/revert_errors'); +import { ExchangeRevertErrors } from '../../src'; import { artifacts } from '../artifacts'; diff --git a/contracts/exchange/test/wrapper_unit_tests.ts b/contracts/exchange/test/wrapper_unit_tests.ts index 96d0327744..b518c1d109 100644 --- a/contracts/exchange/test/wrapper_unit_tests.ts +++ b/contracts/exchange/test/wrapper_unit_tests.ts @@ -11,13 +11,11 @@ import { } from '@0x/contracts-test-utils'; import { ReferenceFunctions as UtilReferenceFunctions, SafeMathRevertErrors } from '@0x/contracts-utils'; import { FillResults, Order } from '@0x/types'; -import { AnyRevertError, BigNumber, StringRevertError } from '@0x/utils'; +import { AnyRevertError, BigNumber, ExchangeRevertErrors, 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 { TestFillRoundingContract, diff --git a/contracts/staking/src/fixed_math_revert_errors.ts b/contracts/staking/src/fixed_math_revert_errors.ts deleted file mode 100644 index e0206d0be4..0000000000 --- a/contracts/staking/src/fixed_math_revert_errors.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { BigNumber, RevertError } from '@0x/utils'; - -// tslint:disable:max-classes-per-file - -export enum ValueErrorCodes { - TooSmall, - TooLarge, -} - -export enum BinOpErrorCodes { - AdditionOverflow, - MultiplicationOverflow, - DivisionByZero, - DivisionOverflow, -} - -export class SignedValueError extends RevertError { - constructor(error?: ValueErrorCodes, n?: BigNumber | number | string) { - super('SignedValueError', 'SignedValueError(uint8 error, int256 n)', { - error, - n, - }); - } -} - -export class UnsignedValueError extends RevertError { - constructor(error?: ValueErrorCodes, n?: BigNumber | number | string) { - super('UnsignedValueError', 'UnsignedValueError(uint8 error, uint256 n)', { - error, - n, - }); - } -} - -export class BinOpError extends RevertError { - constructor(error?: BinOpErrorCodes, a?: BigNumber | number | string, b?: BigNumber | number | string) { - super('BinOpError', 'BinOpError(uint8 error, int256 a, int256 b)', { - error, - a, - b, - }); - } -} - -const types = [SignedValueError, UnsignedValueError, BinOpError]; - -// Register the types we've defined. -for (const type of types) { - RevertError.registerType(type); -} diff --git a/contracts/staking/src/index.ts b/contracts/staking/src/index.ts index 277af9e0d0..7b2d5b8e54 100644 --- a/contracts/staking/src/index.ts +++ b/contracts/staking/src/index.ts @@ -41,8 +41,7 @@ export { IStakingEventsRewardsPaidEventArgs, } from './wrappers'; export { artifacts } from './artifacts'; -export import FixedMathRevertErrors = require('./fixed_math_revert_errors'); -export import StakingRevertErrors = require('./staking_revert_errors'); +export { StakingRevertErrors, FixedMathRevertErrors } from '@0x/utils'; export { constants } from './constants'; export { StakeInfo, diff --git a/contracts/staking/src/staking_revert_errors.ts b/contracts/staking/src/staking_revert_errors.ts deleted file mode 100644 index 81c0c983ee..0000000000 --- a/contracts/staking/src/staking_revert_errors.ts +++ /dev/null @@ -1,204 +0,0 @@ -import { BigNumber, RevertError } from '@0x/utils'; - -// tslint:disable:max-classes-per-file - -export enum MakerPoolAssignmentErrorCodes { - MakerAddressAlreadyRegistered, - MakerAddressNotRegistered, - MakerAddressNotPendingAdd, - PoolIsFull, -} - -export enum OperatorShareErrorCodes { - OperatorShareTooLarge, - CanOnlyDecreaseOperatorShare, -} - -export enum InvalidParamValueErrorCodes { - InvalidCobbDouglasAlpha, - InvalidRewardDelegatedStakeWeight, - InvalidMaximumMakersInPool, - InvalidMinimumPoolStake, - InvalidEpochDuration, -} - -export enum InitializationErrorCodes { - MixinSchedulerAlreadyInitialized, - MixinParamsAlreadyInitialized, -} - -export enum ExchangeManagerErrorCodes { - ExchangeAlreadyRegistered, - ExchangeNotRegistered, -} - -export class OnlyCallableByExchangeError extends RevertError { - constructor(senderAddress?: string) { - super('OnlyCallableByExchangeError', 'OnlyCallableByExchangeError(address senderAddress)', { senderAddress }); - } -} - -export class ExchangeManagerError extends RevertError { - constructor(error?: ExchangeManagerErrorCodes, senderAddress?: string) { - super('ExchangeManagerError', 'ExchangeManagerError(uint8 errorCode, address senderAddress)', { - error, - senderAddress, - }); - } -} - -export class InsufficientBalanceError extends RevertError { - constructor(amount?: BigNumber | number | string, balance?: BigNumber | number | string) { - super('InsufficientBalanceError', 'InsufficientBalanceError(uint256 amount, uint256 balance)', { - amount, - balance, - }); - } -} - -export class OnlyCallableByPoolOperatorError extends RevertError { - constructor(senderAddress?: string, poolId?: string) { - super( - 'OnlyCallableByPoolOperatorError', - 'OnlyCallableByPoolOperatorError(address senderAddress, bytes32 poolId)', - { senderAddress, poolId }, - ); - } -} - -export class MakerPoolAssignmentError extends RevertError { - constructor(error?: MakerPoolAssignmentErrorCodes, makerAddress?: string, poolId?: string) { - super( - 'MakerPoolAssignmentError', - 'MakerPoolAssignmentError(uint8 error, address makerAddress, bytes32 poolId)', - { - error, - makerAddress, - poolId, - }, - ); - } -} - -export class BlockTimestampTooLowError extends RevertError { - constructor(epochEndTime?: BigNumber | number | string, currentBlockTimestamp?: BigNumber | number | string) { - super( - 'BlockTimestampTooLowError', - 'BlockTimestampTooLowError(uint256 epochEndTime, uint256 currentBlockTimestamp)', - { epochEndTime, currentBlockTimestamp }, - ); - } -} - -export class OnlyCallableByStakingContractError extends RevertError { - constructor(senderAddress?: string) { - super('OnlyCallableByStakingContractError', 'OnlyCallableByStakingContractError(address senderAddress)', { - senderAddress, - }); - } -} - -export class OnlyCallableIfInCatastrophicFailureError extends RevertError { - constructor() { - super('OnlyCallableIfInCatastrophicFailureError', 'OnlyCallableIfInCatastrophicFailureError()', {}); - } -} - -export class OnlyCallableIfNotInCatastrophicFailureError extends RevertError { - constructor() { - super('OnlyCallableIfNotInCatastrophicFailureError', 'OnlyCallableIfNotInCatastrophicFailureError()', {}); - } -} - -export class OperatorShareError extends RevertError { - constructor(error?: OperatorShareErrorCodes, poolId?: string, operatorShare?: BigNumber | number | string) { - super('OperatorShareError', 'OperatorShareError(uint8 error, bytes32 poolId, uint32 operatorShare)', { - error, - poolId, - operatorShare, - }); - } -} - -export class PoolExistenceError extends RevertError { - constructor(poolId?: string, alreadyExists?: boolean) { - super('PoolExistenceError', 'PoolExistenceError(bytes32 poolId, bool alreadyExists)', { - poolId, - alreadyExists, - }); - } -} - -export class InvalidParamValueError extends RevertError { - constructor(error?: InvalidParamValueErrorCodes) { - super('InvalidParamValueError', 'InvalidParamValueError(uint8 error)', { - error, - }); - } -} - -export class InvalidProtocolFeePaymentError extends RevertError { - constructor( - expectedProtocolFeePaid?: BigNumber | number | string, - actualProtocolFeePaid?: BigNumber | number | string, - ) { - super( - 'InvalidProtocolFeePaymentError', - 'InvalidProtocolFeePaymentError(uint256 expectedProtocolFeePaid, uint256 actualProtocolFeePaid)', - { expectedProtocolFeePaid, actualProtocolFeePaid }, - ); - } -} - -export class InitializationError extends RevertError { - constructor(error?: InitializationErrorCodes) { - super('InitializationError', 'InitializationError(uint8 error)', { error }); - } -} - -export class ProxyDestinationCannotBeNilError extends RevertError { - constructor() { - super('ProxyDestinationCannotBeNilError', 'ProxyDestinationCannotBeNilError()', {}); - } -} - -export class PreviousEpochNotFinalizedError extends RevertError { - constructor(closingEpoch?: BigNumber | number | string, unfinalizedPoolsRemaining?: BigNumber | number | string) { - super( - 'PreviousEpochNotFinalizedError', - 'PreviousEpochNotFinalizedError(uint256 closingEpoch, uint256 unfinalizedPoolsRemaining)', - { closingEpoch, unfinalizedPoolsRemaining }, - ); - } -} - -export class PoolNotFinalizedError extends RevertError { - constructor(poolId: string, epoch: BigNumber | number | string) { - super('PoolNotFinalizedError', 'PoolNotFinalizedError(bytes32 poolId, uint256 epoch)', { poolId, epoch }); - } -} - -const types = [ - BlockTimestampTooLowError, - ExchangeManagerError, - InitializationError, - InsufficientBalanceError, - InvalidProtocolFeePaymentError, - InvalidParamValueError, - MakerPoolAssignmentError, - OnlyCallableByExchangeError, - OnlyCallableByPoolOperatorError, - OnlyCallableByStakingContractError, - OnlyCallableIfInCatastrophicFailureError, - OnlyCallableIfNotInCatastrophicFailureError, - OperatorShareError, - PoolExistenceError, - PreviousEpochNotFinalizedError, - ProxyDestinationCannotBeNilError, - PoolNotFinalizedError, -]; - -// Register the types we've defined. -for (const type of types) { - RevertError.registerType(type); -} diff --git a/contracts/staking/test/migration_test.ts b/contracts/staking/test/migration_test.ts index aebb814abe..2960a5b2ff 100644 --- a/contracts/staking/test/migration_test.ts +++ b/contracts/staking/test/migration_test.ts @@ -1,9 +1,8 @@ import { blockchainTests, constants, expect, filterLogsToArguments } from '@0x/contracts-test-utils'; import { AuthorizableRevertErrors } from '@0x/contracts-utils'; -import { BigNumber, StringRevertError } from '@0x/utils'; +import { BigNumber, StakingRevertErrors, 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 142a71394f..9581fcec20 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/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 098aa92a27..cff54d80e0 100644 --- a/contracts/staking/test/rewards_test.ts +++ b/contracts/staking/test/rewards_test.ts @@ -1,9 +1,8 @@ import { ERC20Wrapper } from '@0x/contracts-asset-proxy'; import { blockchainTests, constants, describe, expect, shortZip } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, StakingRevertErrors } 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 a530ad28a4..75d791c3f1 100644 --- a/contracts/staking/test/stake_test.ts +++ b/contracts/staking/test/stake_test.ts @@ -1,9 +1,8 @@ import { ERC20Wrapper } from '@0x/contracts-asset-proxy'; import { blockchainTests, describe } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, StakingRevertErrors } 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 af3302f1c2..df1e8fef28 100644 --- a/contracts/staking/test/unit_tests/exchange_test.ts +++ b/contracts/staking/test/unit_tests/exchange_test.ts @@ -2,7 +2,7 @@ import { blockchainTests, expect } from '@0x/contracts-test-utils'; import { AuthorizableRevertErrors } from '@0x/contracts-utils'; import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; -import StakingRevertErrors = require('../../src/staking_revert_errors'); +import { StakingRevertErrors } from '../../src'; import { artifacts } from '../artifacts'; import { diff --git a/contracts/staking/test/unit_tests/finalizer_test.ts b/contracts/staking/test/unit_tests/finalizer_test.ts index bf3f581b28..1a6f278559 100644 --- a/contracts/staking/test/unit_tests/finalizer_test.ts +++ b/contracts/staking/test/unit_tests/finalizer_test.ts @@ -11,8 +11,8 @@ import { BigNumber } from '@0x/utils'; import { LogEntry } from 'ethereum-types'; import * as _ from 'lodash'; +import { StakingRevertErrors } from '../../src'; 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 8b08e74e41..1c0ade0fd5 100644 --- a/contracts/staking/test/unit_tests/lib_fixed_math_test.ts +++ b/contracts/staking/test/unit_tests/lib_fixed_math_test.ts @@ -3,7 +3,7 @@ import { BigNumber } from '@0x/utils'; import { Decimal } from 'decimal.js'; import * as _ from 'lodash'; -import FixedMathRevertErrors = require('../../src/fixed_math_revert_errors'); +import { FixedMathRevertErrors } from '../../src'; import { assertRoughlyEquals, fromFixed, toDecimal, toFixed } from '../utils/number_utils'; import { artifacts } from '../artifacts'; diff --git a/contracts/staking/test/unit_tests/mixin_scheduler_test.ts b/contracts/staking/test/unit_tests/mixin_scheduler_test.ts index 8e01f061cd..3595dc6829 100644 --- a/contracts/staking/test/unit_tests/mixin_scheduler_test.ts +++ b/contracts/staking/test/unit_tests/mixin_scheduler_test.ts @@ -2,8 +2,8 @@ import { blockchainTests, constants, expect, verifyEventsFromLogs } from '@0x/co import { BigNumber } from '@0x/utils'; import { LogWithDecodedArgs } from 'ethereum-types'; +import { StakingRevertErrors } from '../../src'; 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/protocol_fees_test.ts b/contracts/staking/test/unit_tests/protocol_fees_test.ts index 06634c5667..f9e12e4b1b 100644 --- a/contracts/staking/test/unit_tests/protocol_fees_test.ts +++ b/contracts/staking/test/unit_tests/protocol_fees_test.ts @@ -11,7 +11,7 @@ import { BigNumber } from '@0x/utils'; import { LogEntry } from 'ethereum-types'; import * as _ from 'lodash'; -import StakingRevertErrors = require('../../src/staking_revert_errors'); +import { StakingRevertErrors } from '../../src'; import { artifacts } from '../artifacts'; import { diff --git a/contracts/staking/test/unit_tests/stake_test.ts b/contracts/staking/test/unit_tests/stake_test.ts index defd6b58d6..3688ac7fa9 100644 --- a/contracts/staking/test/unit_tests/stake_test.ts +++ b/contracts/staking/test/unit_tests/stake_test.ts @@ -12,7 +12,7 @@ import { import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; -import StakingRevertErrors = require('../../src/staking_revert_errors'); +import { StakingRevertErrors } from '../../src'; import { StakeStatus } from '../../src/types'; import { artifacts } from '../artifacts'; diff --git a/contracts/staking/test/unit_tests/staking_proxy_test.ts b/contracts/staking/test/unit_tests/staking_proxy_test.ts index 5d72266ca2..bc6a19fe67 100644 --- a/contracts/staking/test/unit_tests/staking_proxy_test.ts +++ b/contracts/staking/test/unit_tests/staking_proxy_test.ts @@ -11,8 +11,8 @@ import { TestStakingProxyUnitContract, } from '../wrappers'; +import { StakingRevertErrors } from '../../src'; 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 fc94715ac5..adceab2c84 100644 --- a/contracts/staking/test/unit_tests/zrx_vault_test.ts +++ b/contracts/staking/test/unit_tests/zrx_vault_test.ts @@ -13,8 +13,8 @@ import { RevertReason } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; +import { StakingRevertErrors } from '../../src'; import { constants as stakingConstants } from '../../src/constants'; -import StakingRevertErrors = require('../../src/staking_revert_errors'); import { artifacts } from '../artifacts'; import { diff --git a/contracts/utils/src/authorizable_revert_errors.ts b/contracts/utils/src/authorizable_revert_errors.ts deleted file mode 100644 index dd001d5e44..0000000000 --- a/contracts/utils/src/authorizable_revert_errors.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { BigNumber, RevertError } from '@0x/utils'; - -// tslint:disable:max-classes-per-file -export class AuthorizedAddressMismatchError extends RevertError { - constructor(authorized?: string, target?: string) { - super('AuthorizedAddressMismatchError', 'AuthorizedAddressMismatchError(address authorized, address target)', { - authorized, - target, - }); - } -} - -export class IndexOutOfBoundsError extends RevertError { - constructor(index?: BigNumber, len?: BigNumber) { - super('IndexOutOfBoundsError', 'IndexOutOfBoundsError(uint256 index, uint256 len)', { index, len }); - } -} - -export class SenderNotAuthorizedError extends RevertError { - constructor(sender?: string) { - super('SenderNotAuthorizedError', 'SenderNotAuthorizedError(address sender)', { sender }); - } -} - -export class TargetAlreadyAuthorizedError extends RevertError { - constructor(target?: string) { - super('TargetAlreadyAuthorizedError', 'TargetAlreadyAuthorizedError(address target)', { target }); - } -} - -export class TargetNotAuthorizedError extends RevertError { - constructor(target?: string) { - super('TargetNotAuthorizedError', 'TargetNotAuthorizedError(address target)', { target }); - } -} - -export class ZeroCantBeAuthorizedError extends RevertError { - constructor() { - super('ZeroCantBeAuthorizedError', 'ZeroCantBeAuthorizedError()', {}); - } -} - -const types = [ - AuthorizedAddressMismatchError, - IndexOutOfBoundsError, - SenderNotAuthorizedError, - TargetAlreadyAuthorizedError, - TargetNotAuthorizedError, - ZeroCantBeAuthorizedError, -]; - -// Register the types we've defined. -for (const type of types) { - RevertError.registerType(type); -} diff --git a/contracts/utils/src/index.ts b/contracts/utils/src/index.ts index c5f5bb8b4e..f5eefb8b42 100644 --- a/contracts/utils/src/index.ts +++ b/contracts/utils/src/index.ts @@ -4,9 +4,11 @@ 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'); +export { + AuthorizableRevertErrors, + LibAddressArrayRevertErrors, + LibBytesRevertErrors, + OwnableRevertErrors, + ReentrancyGuardRevertErrors, + SafeMathRevertErrors, +} from '@0x/utils'; diff --git a/contracts/utils/src/lib_address_array_revert_errors.ts b/contracts/utils/src/lib_address_array_revert_errors.ts deleted file mode 100644 index fdd7c4fbcd..0000000000 --- a/contracts/utils/src/lib_address_array_revert_errors.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { BigNumber, RevertError } from '@0x/utils'; - -export class MismanagedMemoryError extends RevertError { - constructor(freeMemPtr?: BigNumber, addressArrayEndPtr?: BigNumber) { - super('MismanagedMemoryError', 'MismanagedMemoryError(uint256 freeMemPtr, uint256 addressArrayEndPtr)', { - freeMemPtr, - addressArrayEndPtr, - }); - } -} - -// Register the MismanagedMemoryError type -RevertError.registerType(MismanagedMemoryError); diff --git a/contracts/utils/src/lib_bytes_revert_errors.ts b/contracts/utils/src/lib_bytes_revert_errors.ts deleted file mode 100644 index 3d7f4fa0f9..0000000000 --- a/contracts/utils/src/lib_bytes_revert_errors.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { BigNumber, RevertError } from '@0x/utils'; - -export enum InvalidByteOperationErrorCodes { - FromLessThanOrEqualsToRequired, - ToLessThanOrEqualsLengthRequired, - LengthGreaterThanZeroRequired, - LengthGreaterThanOrEqualsFourRequired, - LengthGreaterThanOrEqualsTwentyRequired, - LengthGreaterThanOrEqualsThirtyTwoRequired, - LengthGreaterThanOrEqualsNestedBytesLengthRequired, - DestinationLengthGreaterThanOrEqualSourceLengthRequired, -} - -export class InvalidByteOperationError extends RevertError { - constructor(error?: InvalidByteOperationErrorCodes, offset?: BigNumber, required?: BigNumber) { - super('InvalidByteOperationError', 'InvalidByteOperationError(uint8 error, uint256 offset, uint256 required)', { - error, - offset, - required, - }); - } -} - -// Register the InvalidByteOperationError type -RevertError.registerType(InvalidByteOperationError); diff --git a/contracts/utils/src/ownable_revert_errors.ts b/contracts/utils/src/ownable_revert_errors.ts deleted file mode 100644 index dd61036876..0000000000 --- a/contracts/utils/src/ownable_revert_errors.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { RevertError } from '@0x/utils'; - -// tslint:disable:max-classes-per-file -export class OnlyOwnerError extends RevertError { - constructor(sender?: string, owner?: string) { - super('OnlyOwnerError', 'OnlyOwnerError(address sender, address owner)', { - sender, - owner, - }); - } -} - -export class TransferOwnerToZeroError extends RevertError { - constructor() { - super('TransferOwnerToZeroError', 'TransferOwnerToZeroError()', {}); - } -} - -const types = [OnlyOwnerError, TransferOwnerToZeroError]; - -// Register the types we've defined. -for (const type of types) { - RevertError.registerType(type); -} diff --git a/contracts/utils/src/reentrancy_guard_revert_errors.ts b/contracts/utils/src/reentrancy_guard_revert_errors.ts deleted file mode 100644 index 1c39c6d5c4..0000000000 --- a/contracts/utils/src/reentrancy_guard_revert_errors.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { RevertError } from '@0x/utils'; - -export class IllegalReentrancyError extends RevertError { - constructor() { - super('IllegalReentrancyError', 'IllegalReentrancyError()', {}); - } -} - -// Register the IllegalReentrancyError type -RevertError.registerType(IllegalReentrancyError); diff --git a/contracts/utils/src/reference_functions.ts b/contracts/utils/src/reference_functions.ts index 3b384fb71f..cd67f4a089 100644 --- a/contracts/utils/src/reference_functions.ts +++ b/contracts/utils/src/reference_functions.ts @@ -1,6 +1,4 @@ -import { BigNumber } from '@0x/utils'; - -import SafeMathRevertErrors = require('./safe_math_revert_errors'); +import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; const MAX_UINT256 = new BigNumber(2).pow(256).minus(1); diff --git a/contracts/utils/src/safe_math_revert_errors.ts b/contracts/utils/src/safe_math_revert_errors.ts deleted file mode 100644 index 499dc2009e..0000000000 --- a/contracts/utils/src/safe_math_revert_errors.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { BigNumber, RevertError } from '@0x/utils'; - -// tslint:disable:max-classes-per-file - -export enum BinOpErrorCodes { - AdditionOverflow, - MultiplicationOverflow, - SubtractionUnderflow, - DivisionByZero, -} - -export enum DowncastErrorCodes { - ValueTooLargeToDowncastToUint32, - ValueTooLargeToDowncastToUint64, - ValueTooLargeToDowncastToUint96, -} - -export class Uint256BinOpError extends RevertError { - constructor(error?: BinOpErrorCodes, a?: BigNumber, b?: BigNumber) { - super('Uint256BinOpError', 'Uint256BinOpError(uint8 error, uint256 a, uint256 b)', { - error, - a, - b, - }); - } -} - -export class Uint96BinOpError extends RevertError { - constructor(error?: BinOpErrorCodes, a?: BigNumber, b?: BigNumber) { - super('Uint96BinOpError', 'Uint96BinOpError(uint8 error, uint96 a, uint96 b)', { - error, - a, - b, - }); - } -} - -export class Uint64BinOpError extends RevertError { - constructor(error?: BinOpErrorCodes, a?: BigNumber, b?: BigNumber) { - super('Uint64BinOpError', 'Uint64BinOpError(uint8 error, uint64 a, uint64 b)', { - error, - a, - b, - }); - } -} - -export class Uint256DowncastError extends RevertError { - constructor(error?: DowncastErrorCodes, a?: BigNumber) { - super('Uint256DowncastError', 'Uint256DowncastError(uint8 error, uint256 a)', { - error, - a, - }); - } -} - -const types = [Uint256BinOpError, Uint96BinOpError, Uint64BinOpError, Uint256DowncastError]; - -// Register the types we've defined. -for (const type of types) { - RevertError.registerType(type); -} diff --git a/contracts/utils/test/authorizable.ts b/contracts/utils/test/authorizable.ts index 60850ada5b..c48852500b 100644 --- a/contracts/utils/test/authorizable.ts +++ b/contracts/utils/test/authorizable.ts @@ -1,10 +1,7 @@ import { blockchainTests, constants, expect } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; +import { AuthorizableRevertErrors, BigNumber, OwnableRevertErrors } from '@0x/utils'; import * as _ from 'lodash'; -import AuthorizableRevertErrors = require('../src/authorizable_revert_errors'); -import OwnableRevertErrors = require('../src/ownable_revert_errors'); - import { artifacts } from './artifacts'; import { TestAuthorizableContract } from './wrappers'; diff --git a/contracts/utils/test/lib_address_array.ts b/contracts/utils/test/lib_address_array.ts index de256709bb..df4116b661 100644 --- a/contracts/utils/test/lib_address_array.ts +++ b/contracts/utils/test/lib_address_array.ts @@ -1,11 +1,9 @@ import { chaiSetup, provider, randomAddress, txDefaults, web3Wrapper } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, LibAddressArrayRevertErrors } 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 ea55d7cff2..e8feeb61d0 100644 --- a/contracts/utils/test/lib_bytes.ts +++ b/contracts/utils/test/lib_bytes.ts @@ -1,11 +1,9 @@ import { blockchainTests, constants, expect } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, LibBytesRevertErrors } 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 42121106d0..f6a34c391f 100644 --- a/contracts/utils/test/lib_safe_math.ts +++ b/contracts/utils/test/lib_safe_math.ts @@ -1,9 +1,8 @@ import { blockchainTests, constants, describe, expect } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, SafeMathRevertErrors } 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 e802a0b679..471edcd9a5 100644 --- a/contracts/utils/test/ownable.ts +++ b/contracts/utils/test/ownable.ts @@ -1,6 +1,5 @@ import { blockchainTests, constants, expect, filterLogsToArguments } from '@0x/contracts-test-utils'; - -import OwnableRevertErrors = require('../src/ownable_revert_errors'); +import { OwnableRevertErrors } from '@0x/utils'; 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 438fccf63a..ec8d6ff282 100644 --- a/contracts/utils/test/reentrancy_guard.ts +++ b/contracts/utils/test/reentrancy_guard.ts @@ -3,7 +3,7 @@ import { BlockchainLifecycle } from '@0x/dev-utils'; import * as chai from 'chai'; import * as _ from 'lodash'; -import ReentrancyGuardRevertErrors = require('../src/reentrancy_guard_revert_errors'); +import { ReentrancyGuardRevertErrors } from '@0x/utils'; 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 4b6393715b..f604633e2b 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/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json index 3ba8158a16..1d18085ccf 100644 --- a/packages/utils/CHANGELOG.json +++ b/packages/utils/CHANGELOG.json @@ -3,7 +3,8 @@ "version": "4.6.0-beta.3", "changes": [ { - "note": "Re-export all `RevertErrors`" + "note": "Re-export all `RevertErrors`", + "pr": 2362 } ] }, diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 46f1013394..1a25cb41d6 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -26,84 +26,15 @@ export { AnyRevertError, } from './revert_error'; -export { - AssetProxyDispatchError, - AssetProxyDispatchErrorCode, - AssetProxyExistsError, - AssetProxyTransferError, - BatchMatchOrdersError, - BatchMatchOrdersErrorCodes, - EIP1271SignatureError, - ExchangeContextErrorCodes, - ExchangeInvalidContextError, - FillError, - FillErrorCode, - IncompleteFillError, - IncompleteFillErrorCode, - NegativeSpreadError, - OrderEpochError, - OrderStatusError, - PayProtocolFeeError, - SignatureError, - SignatureErrorCode, - SignatureValidatorNotApprovedError, - SignatureWalletError, - TransactionError, - TransactionErrorCode, - TransactionExecutionError, - TransactionGasPriceError, - TransactionInvalidContextError, -} from './revert_errors/exchange/revert_errors'; - -export { - CompleteBuyFailedError, - DefaultFunctionWethContractOnlyError, - Erc721AmountMustEqualOneError, - FeePercentageTooLargeError, - InsufficientEthForFeeError, - MsgValueCannotEqualZeroError, - OverspentWethError, - UnregisteredAssetProxyError, - UnsupportedAssetProxyError, - UnsupportedFeeError, -} from './revert_errors/exchange-forwarder/revert_errors'; - -export { DivisionByZeroError, RoundingError } from './revert_errors/exchange-libs/lib_math_revert_errors'; -export { - BinOpError, - BinOpErrorCodes as StakingBinOpErrorCodes, - SignedValueError, - UnsignedValueError, - ValueErrorCodes, -} from './revert_errors/staking/fixed_math_revert_errors'; - -export { - AuthorizedAddressMismatchError, - IndexOutOfBoundsError, - SenderNotAuthorizedError, - TargetAlreadyAuthorizedError, - TargetNotAuthorizedError, - ZeroCantBeAuthorizedError, -} from './revert_errors/utils/authorizable_revert_errors'; -export { MismanagedMemoryError } from './revert_errors/utils/lib_address_array_revert_errors'; -export { - InvalidByteOperationError, - InvalidByteOperationErrorCodes, -} from './revert_errors/utils/lib_bytes_revert_errors'; -export { OnlyOwnerError, TransferOwnerToZeroError } from './revert_errors/utils/ownable_revert_errors'; -export { IllegalReentrancyError } from './revert_errors/utils/reentrancy_guard_revert_errors'; -export { - BinOpErrorCodes, - DowncastErrorCodes, - Uint256BinOpError, - Uint256DowncastError, - Uint64BinOpError, - Uint96BinOpError, -} from './revert_errors/utils/safe_math_revert_errors'; -export { - ApprovalExpiredError, - InvalidApprovalSignatureError, - InvalidOriginError, - SignatureError as CoordinatorSignatureError, - SignatureErrorCodes, -} from './revert_errors/coordinator/revert_errors'; +export import CoordinatorRevertErrors = require('./revert_errors/coordinator/revert_errors'); +export import ExchangeForwarderRevertErrors = require('./revert_errors/exchange-forwarder/revert_errors'); +export import LibMathRevertErrors = require('./revert_errors/exchange-libs/lib_math_revert_errors'); +export import ExchangeRevertErrors = require('./revert_errors/exchange/revert_errors'); +export import FixedMathRevertErrors = require('./revert_errors/staking/fixed_math_revert_errors'); +export import StakingRevertErrors = require('./revert_errors/staking/staking_revert_errors'); +export import AuthorizableRevertErrors = require('./revert_errors/utils/authorizable_revert_errors'); +export import LibAddressArrayRevertErrors = require('./revert_errors/utils/lib_address_array_revert_errors'); +export import LibBytesRevertErrors = require('./revert_errors/utils/lib_bytes_revert_errors'); +export import OwnableRevertErrors = require('./revert_errors/utils/ownable_revert_errors'); +export import ReentrancyGuardRevertErrors = require('./revert_errors/utils/reentrancy_guard_revert_errors'); +export import SafeMathRevertErrors = require('./revert_errors/utils/safe_math_revert_errors');