From 9c422412696a09b60aa3593f234e1b030599631d Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Fri, 22 Nov 2019 12:09:27 +1100 Subject: [PATCH 1/4] Re-export the RevertErrors --- packages/utils/CHANGELOG.json | 8 + packages/utils/src/index.ts | 82 +++++ .../coordinator/revert_errors.ts | 53 ++++ .../exchange-forwarder/revert_errors.ts | 102 +++++++ .../exchange-libs/lib_math_revert_errors.ts | 33 ++ .../revert_errors/exchange/revert_errors.ts | 289 ++++++++++++++++++ .../staking/fixed_math_revert_errors.ts | 51 ++++ .../staking/staking_revert_errors.ts | 205 +++++++++++++ .../utils/authorizable_revert_errors.ts | 56 ++++ .../utils/lib_address_array_revert_errors.ts | 14 + .../utils/lib_bytes_revert_errors.ts | 26 ++ .../utils/ownable_revert_errors.ts | 24 ++ .../utils/reentrancy_guard_revert_errors.ts | 10 + .../utils/safe_math_revert_errors.ts | 63 ++++ 14 files changed, 1016 insertions(+) create mode 100644 packages/utils/src/revert_errors/coordinator/revert_errors.ts create mode 100644 packages/utils/src/revert_errors/exchange-forwarder/revert_errors.ts create mode 100644 packages/utils/src/revert_errors/exchange-libs/lib_math_revert_errors.ts create mode 100644 packages/utils/src/revert_errors/exchange/revert_errors.ts create mode 100644 packages/utils/src/revert_errors/staking/fixed_math_revert_errors.ts create mode 100644 packages/utils/src/revert_errors/staking/staking_revert_errors.ts create mode 100644 packages/utils/src/revert_errors/utils/authorizable_revert_errors.ts create mode 100644 packages/utils/src/revert_errors/utils/lib_address_array_revert_errors.ts create mode 100644 packages/utils/src/revert_errors/utils/lib_bytes_revert_errors.ts create mode 100644 packages/utils/src/revert_errors/utils/ownable_revert_errors.ts create mode 100644 packages/utils/src/revert_errors/utils/reentrancy_guard_revert_errors.ts create mode 100644 packages/utils/src/revert_errors/utils/safe_math_revert_errors.ts diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json index e0994b4fdb..3ba8158a16 100644 --- a/packages/utils/CHANGELOG.json +++ b/packages/utils/CHANGELOG.json @@ -1,4 +1,12 @@ [ + { + "version": "4.6.0-beta.3", + "changes": [ + { + "note": "Re-export all `RevertErrors`" + } + ] + }, { "version": "4.6.0-beta.2", "changes": [ diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 81de561a40..46f1013394 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -25,3 +25,85 @@ export { StringRevertError, 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'; diff --git a/packages/utils/src/revert_errors/coordinator/revert_errors.ts b/packages/utils/src/revert_errors/coordinator/revert_errors.ts new file mode 100644 index 0000000000..a117890b38 --- /dev/null +++ b/packages/utils/src/revert_errors/coordinator/revert_errors.ts @@ -0,0 +1,53 @@ +import { BigNumber } from '../../configured_bignumber'; +import { RevertError } from '../../revert_error'; + +// 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/packages/utils/src/revert_errors/exchange-forwarder/revert_errors.ts b/packages/utils/src/revert_errors/exchange-forwarder/revert_errors.ts new file mode 100644 index 0000000000..bf4da2bd69 --- /dev/null +++ b/packages/utils/src/revert_errors/exchange-forwarder/revert_errors.ts @@ -0,0 +1,102 @@ +import { BigNumber } from '../../configured_bignumber'; +import { RevertError } from '../../revert_error'; + +// 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/packages/utils/src/revert_errors/exchange-libs/lib_math_revert_errors.ts b/packages/utils/src/revert_errors/exchange-libs/lib_math_revert_errors.ts new file mode 100644 index 0000000000..860fd3223b --- /dev/null +++ b/packages/utils/src/revert_errors/exchange-libs/lib_math_revert_errors.ts @@ -0,0 +1,33 @@ +import * as _ from 'lodash'; + +import { BigNumber } from '../../configured_bignumber'; +import { RevertError } from '../../revert_error'; + +// 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/packages/utils/src/revert_errors/exchange/revert_errors.ts b/packages/utils/src/revert_errors/exchange/revert_errors.ts new file mode 100644 index 0000000000..83cece37fb --- /dev/null +++ b/packages/utils/src/revert_errors/exchange/revert_errors.ts @@ -0,0 +1,289 @@ +import { OrderStatus } from '@0x/types'; +import * as _ from 'lodash'; + +import { BigNumber } from '../../configured_bignumber'; +import { RevertError } from '../../revert_error'; + +// 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/packages/utils/src/revert_errors/staking/fixed_math_revert_errors.ts b/packages/utils/src/revert_errors/staking/fixed_math_revert_errors.ts new file mode 100644 index 0000000000..fafe47cf2d --- /dev/null +++ b/packages/utils/src/revert_errors/staking/fixed_math_revert_errors.ts @@ -0,0 +1,51 @@ +import { BigNumber } from '../../configured_bignumber'; +import { RevertError } from '../../revert_error'; + +// 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/packages/utils/src/revert_errors/staking/staking_revert_errors.ts b/packages/utils/src/revert_errors/staking/staking_revert_errors.ts new file mode 100644 index 0000000000..7cd5a2acd2 --- /dev/null +++ b/packages/utils/src/revert_errors/staking/staking_revert_errors.ts @@ -0,0 +1,205 @@ +import { BigNumber } from '../../configured_bignumber'; +import { RevertError } from '../../revert_error'; + +// 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/packages/utils/src/revert_errors/utils/authorizable_revert_errors.ts b/packages/utils/src/revert_errors/utils/authorizable_revert_errors.ts new file mode 100644 index 0000000000..e7f5d9bf97 --- /dev/null +++ b/packages/utils/src/revert_errors/utils/authorizable_revert_errors.ts @@ -0,0 +1,56 @@ +import { BigNumber } from '../../configured_bignumber'; +import { RevertError } from '../../revert_error'; + +// 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/packages/utils/src/revert_errors/utils/lib_address_array_revert_errors.ts b/packages/utils/src/revert_errors/utils/lib_address_array_revert_errors.ts new file mode 100644 index 0000000000..d9d0e878b9 --- /dev/null +++ b/packages/utils/src/revert_errors/utils/lib_address_array_revert_errors.ts @@ -0,0 +1,14 @@ +import { BigNumber } from '../../configured_bignumber'; +import { RevertError } from '../../revert_error'; + +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/packages/utils/src/revert_errors/utils/lib_bytes_revert_errors.ts b/packages/utils/src/revert_errors/utils/lib_bytes_revert_errors.ts new file mode 100644 index 0000000000..a83e5013ce --- /dev/null +++ b/packages/utils/src/revert_errors/utils/lib_bytes_revert_errors.ts @@ -0,0 +1,26 @@ +import { BigNumber } from '../../configured_bignumber'; +import { RevertError } from '../../revert_error'; + +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/packages/utils/src/revert_errors/utils/ownable_revert_errors.ts b/packages/utils/src/revert_errors/utils/ownable_revert_errors.ts new file mode 100644 index 0000000000..14e18df617 --- /dev/null +++ b/packages/utils/src/revert_errors/utils/ownable_revert_errors.ts @@ -0,0 +1,24 @@ +import { RevertError } from '../../revert_error'; + +// 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/packages/utils/src/revert_errors/utils/reentrancy_guard_revert_errors.ts b/packages/utils/src/revert_errors/utils/reentrancy_guard_revert_errors.ts new file mode 100644 index 0000000000..75cf0c7fe1 --- /dev/null +++ b/packages/utils/src/revert_errors/utils/reentrancy_guard_revert_errors.ts @@ -0,0 +1,10 @@ +import { RevertError } from '../../revert_error'; + +export class IllegalReentrancyError extends RevertError { + constructor() { + super('IllegalReentrancyError', 'IllegalReentrancyError()', {}); + } +} + +// Register the IllegalReentrancyError type +RevertError.registerType(IllegalReentrancyError); diff --git a/packages/utils/src/revert_errors/utils/safe_math_revert_errors.ts b/packages/utils/src/revert_errors/utils/safe_math_revert_errors.ts new file mode 100644 index 0000000000..b90f11b1d4 --- /dev/null +++ b/packages/utils/src/revert_errors/utils/safe_math_revert_errors.ts @@ -0,0 +1,63 @@ +import { BigNumber } from '../../configured_bignumber'; +import { RevertError } from '../../revert_error'; + +// 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); +} From ad8caa2b51a4a531796dcff529137d859d1b2a41 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Fri, 22 Nov 2019 13:14:25 +1100 Subject: [PATCH 2/4] Remove moved RevertErrors --- contracts/coordinator/src/index.ts | 2 +- contracts/coordinator/src/revert_errors.ts | 52 ---- contracts/coordinator/test/mixins.ts | 4 +- contracts/exchange-forwarder/src/index.ts | 2 +- .../exchange-forwarder/src/revert_errors.ts | 101 ------ .../exchange-forwarder/test/asset_test.ts | 10 +- contracts/exchange-libs/src/index.ts | 2 +- .../src/lib_math_revert_errors.ts | 31 -- .../exchange-libs/src/reference_functions.ts | 4 +- .../exchange-libs/test/lib_fill_results.ts | 3 +- contracts/exchange-libs/test/lib_math.ts | 3 +- .../exchange-libs/test/reference_functions.ts | 3 +- contracts/exchange/src/index.ts | 2 +- contracts/exchange/src/revert_errors.ts | 287 ------------------ contracts/exchange/test/dispatcher.ts | 7 +- contracts/exchange/test/internal.ts | 5 +- .../exchange/test/isolated_fill_order.ts | 4 +- .../test/lib_exchange_rich_error_decoder.ts | 4 +- .../exchange/test/signature_validator.ts | 4 +- contracts/exchange/test/transactions.ts | 3 +- .../exchange/test/transactions_unit_tests.ts | 4 +- .../utils/fill_order_combinatorial_utils.ts | 2 +- contracts/exchange/test/wrapper_unit_tests.ts | 4 +- .../staking/src/fixed_math_revert_errors.ts | 50 --- contracts/staking/src/index.ts | 3 +- .../staking/src/staking_revert_errors.ts | 204 ------------- contracts/staking/test/migration_test.ts | 3 +- contracts/staking/test/pools_test.ts | 2 +- contracts/staking/test/rewards_test.ts | 3 +- contracts/staking/test/stake_test.ts | 3 +- .../staking/test/unit_tests/exchange_test.ts | 2 +- .../staking/test/unit_tests/finalizer_test.ts | 2 +- .../test/unit_tests/lib_fixed_math_test.ts | 2 +- .../test/unit_tests/mixin_scheduler_test.ts | 2 +- .../test/unit_tests/protocol_fees_test.ts | 2 +- .../staking/test/unit_tests/stake_test.ts | 2 +- .../test/unit_tests/staking_proxy_test.ts | 2 +- .../staking/test/unit_tests/zrx_vault_test.ts | 2 +- .../utils/src/authorizable_revert_errors.ts | 55 ---- contracts/utils/src/index.ts | 14 +- .../src/lib_address_array_revert_errors.ts | 13 - .../utils/src/lib_bytes_revert_errors.ts | 25 -- contracts/utils/src/ownable_revert_errors.ts | 24 -- .../src/reentrancy_guard_revert_errors.ts | 10 - contracts/utils/src/reference_functions.ts | 4 +- .../utils/src/safe_math_revert_errors.ts | 62 ---- contracts/utils/test/authorizable.ts | 5 +- contracts/utils/test/lib_address_array.ts | 4 +- contracts/utils/test/lib_bytes.ts | 4 +- contracts/utils/test/lib_safe_math.ts | 3 +- contracts/utils/test/ownable.ts | 3 +- contracts/utils/test/reentrancy_guard.ts | 2 +- contracts/utils/test/reference_functions.ts | 2 +- packages/utils/CHANGELOG.json | 3 +- packages/utils/src/index.ts | 93 +----- 55 files changed, 67 insertions(+), 1086 deletions(-) delete mode 100644 contracts/coordinator/src/revert_errors.ts delete mode 100644 contracts/exchange-forwarder/src/revert_errors.ts delete mode 100644 contracts/exchange-libs/src/lib_math_revert_errors.ts delete mode 100644 contracts/exchange/src/revert_errors.ts delete mode 100644 contracts/staking/src/fixed_math_revert_errors.ts delete mode 100644 contracts/staking/src/staking_revert_errors.ts delete mode 100644 contracts/utils/src/authorizable_revert_errors.ts delete mode 100644 contracts/utils/src/lib_address_array_revert_errors.ts delete mode 100644 contracts/utils/src/lib_bytes_revert_errors.ts delete mode 100644 contracts/utils/src/ownable_revert_errors.ts delete mode 100644 contracts/utils/src/reentrancy_guard_revert_errors.ts delete mode 100644 contracts/utils/src/safe_math_revert_errors.ts 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'); From 89dcbd0229edd82762b58dd4a22e111162f16a81 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Mon, 25 Nov 2019 12:53:28 +1100 Subject: [PATCH 3/4] Fix import of LibBytesRevertErrors --- .../test/forwarder/forwarder_test.ts | 18 ++++++++++-------- .../tests/test/dev-utils/lib_asset_data.ts | 5 ++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/contracts/integrations/test/forwarder/forwarder_test.ts b/contracts/integrations/test/forwarder/forwarder_test.ts index d276c74e07..3c414da4a3 100644 --- a/contracts/integrations/test/forwarder/forwarder_test.ts +++ b/contracts/integrations/test/forwarder/forwarder_test.ts @@ -1,7 +1,7 @@ import { DummyERC20TokenContract } from '@0x/contracts-erc20'; import { DummyERC721TokenContract } from '@0x/contracts-erc721'; import { artifacts as exchangeArtifacts, ExchangeContract } from '@0x/contracts-exchange'; -import { artifacts, ForwarderContract, ForwarderRevertErrors } from '@0x/contracts-exchange-forwarder'; +import { artifacts, ExchangeForwarderRevertErrors, ForwarderContract } from '@0x/contracts-exchange-forwarder'; import { blockchainTests, constants, @@ -127,7 +127,9 @@ blockchainTests('Forwarder integration tests', env => { exchange.address, deployment.tokens.weth.address, ); - await expect(deployForwarder).to.revertWith(new ForwarderRevertErrors.UnregisteredAssetProxyError()); + await expect(deployForwarder).to.revertWith( + new ExchangeForwarderRevertErrors.UnregisteredAssetProxyError(), + ); }); }); blockchainTests.resets('marketSellOrdersWithEth without extra fees', () => { @@ -258,7 +260,7 @@ blockchainTests('Forwarder integration tests', env => { takerFeeAssetData, takerFee: toBaseUnitAmount(1), }); - const revertError = new ForwarderRevertErrors.UnsupportedFeeError(takerFeeAssetData); + const revertError = new ExchangeForwarderRevertErrors.UnsupportedFeeError(takerFeeAssetData); await testFactory.marketSellTestAsync([order], 0.5, { revertError, }); @@ -316,7 +318,7 @@ blockchainTests('Forwarder integration tests', env => { it('should fail if the fee is set too high', async () => { const order = await maker.signOrderAsync(); const forwarderFeePercentage = new BigNumber(6); - const revertError = new ForwarderRevertErrors.FeePercentageTooLargeError( + const revertError = new ExchangeForwarderRevertErrors.FeePercentageTooLargeError( getPercentageOfValue(constants.PERCENTAGE_DENOMINATOR, forwarderFeePercentage), ); await testFactory.marketSellTestAsync([order], 0.5, { @@ -383,7 +385,7 @@ blockchainTests('Forwarder integration tests', env => { }); it('should revert if the amount of ETH sent is too low to fill the makerAssetAmount', async () => { const order = await maker.signOrderAsync(); - const revertError = new ForwarderRevertErrors.CompleteBuyFailedError( + const revertError = new ExchangeForwarderRevertErrors.CompleteBuyFailedError( order.makerAssetAmount.times(0.5), constants.ZERO_AMOUNT, ); @@ -421,7 +423,7 @@ blockchainTests('Forwarder integration tests', env => { takerFeeAssetData, takerFee: toBaseUnitAmount(1), }); - const revertError = new ForwarderRevertErrors.UnsupportedFeeError(takerFeeAssetData); + const revertError = new ExchangeForwarderRevertErrors.UnsupportedFeeError(takerFeeAssetData); await testFactory.marketBuyTestAsync([order], 0.5, { revertError, }); @@ -608,7 +610,7 @@ blockchainTests('Forwarder integration tests', env => { }); it('should fail if the fee is set too high', async () => { const order = await maker.signOrderAsync(); - const revertError = new ForwarderRevertErrors.FeePercentageTooLargeError( + const revertError = new ExchangeForwarderRevertErrors.FeePercentageTooLargeError( getPercentageOfValue(constants.PERCENTAGE_DENOMINATOR, new BigNumber(6)), ); await testFactory.marketBuyTestAsync([order], 0.5, { @@ -623,7 +625,7 @@ blockchainTests('Forwarder integration tests', env => { order.takerAssetAmount.times(0.5).plus(DeploymentManager.protocolFee), forwarderFeePercentage, ); - const revertError = new ForwarderRevertErrors.InsufficientEthForFeeError(ethFee, ethFee.minus(1)); + const revertError = new ExchangeForwarderRevertErrors.InsufficientEthForFeeError(ethFee, ethFee.minus(1)); await testFactory.marketBuyTestAsync([order], 0.5, { ethValueAdjustment: -1, forwarderFeePercentage, diff --git a/contracts/tests/test/dev-utils/lib_asset_data.ts b/contracts/tests/test/dev-utils/lib_asset_data.ts index 76ebe8578a..7b6953a3d0 100644 --- a/contracts/tests/test/dev-utils/lib_asset_data.ts +++ b/contracts/tests/test/dev-utils/lib_asset_data.ts @@ -22,11 +22,10 @@ import { artifacts as exchangeArtifacts, ExchangeContract } from '@0x/contracts- import { chaiSetup, constants, LogDecoder, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { AssetProxyId } from '@0x/types'; -import { BigNumber, providerUtils, StringRevertError } from '@0x/utils'; +import { BigNumber, providerUtils, StringRevertError, LibBytesRevertErrors } from '@0x/utils'; import * as ethUtil from 'ethereumjs-util'; import { artifacts, LibAssetDataContract } from '@0x/contracts-dev-utils'; -import { InvalidByteOperationError } from '@0x/contracts-utils/lib/src/lib_bytes_revert_errors'; chaiSetup.configure(); const expect = chai.expect; @@ -359,7 +358,7 @@ describe('LibAssetData', () => { for (const data of assetData) { const badData = data.substring(0, data.length - 2); // drop one byte but retain assetProxyId await expect(libAssetData.revertIfInvalidAssetData(badData).callAsync()).to.eventually.be.rejectedWith( - InvalidByteOperationError, + LibBytesRevertErrors.InvalidByteOperationError, ); } }); From 389d4d10f1cec7989649665cac6a1d08428ca13c Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 27 Nov 2019 11:58:25 +1100 Subject: [PATCH 4/4] Import from @0x/utils --- .../test/utils/fill_order_combinatorial_utils.ts | 4 +--- contracts/integrations/test/forwarder/bridge_test.ts | 12 ++++++------ contracts/staking/test/unit_tests/exchange_test.ts | 3 +-- contracts/staking/test/unit_tests/finalizer_test.ts | 3 +-- .../staking/test/unit_tests/lib_fixed_math_test.ts | 3 +-- .../staking/test/unit_tests/mixin_scheduler_test.ts | 3 +-- .../staking/test/unit_tests/protocol_fees_test.ts | 4 +--- contracts/staking/test/unit_tests/stake_test.ts | 3 +-- .../staking/test/unit_tests/staking_proxy_test.ts | 3 +-- contracts/staking/test/unit_tests/zrx_vault_test.ts | 4 +--- 10 files changed, 15 insertions(+), 27 deletions(-) diff --git a/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts b/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts index 4089d1acf0..942f8ce2bb 100644 --- a/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts +++ b/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts @@ -8,14 +8,12 @@ import { import { DevUtilsContract } from '@0x/contracts-dev-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 { BigNumber, errorUtils, ExchangeRevertErrors, providerUtils, RevertError, StringRevertError } from '@0x/utils'; import { SupportedProvider, Web3Wrapper } from '@0x/web3-wrapper'; import { LogWithDecodedArgs, TxData } from 'ethereum-types'; import * as _ from 'lodash'; import 'make-promises-safe'; -import { ExchangeRevertErrors } from '../../src'; - import { artifacts } from '../artifacts'; import { ExchangeContract, ExchangeFillEventArgs } from '../wrappers'; diff --git a/contracts/integrations/test/forwarder/bridge_test.ts b/contracts/integrations/test/forwarder/bridge_test.ts index 22061224c7..f5ac2ce510 100644 --- a/contracts/integrations/test/forwarder/bridge_test.ts +++ b/contracts/integrations/test/forwarder/bridge_test.ts @@ -1,6 +1,6 @@ import { IAssetDataContract } from '@0x/contracts-asset-proxy'; import { DummyERC721TokenContract } from '@0x/contracts-erc721'; -import { ForwarderContract, ForwarderRevertErrors } from '@0x/contracts-exchange-forwarder'; +import { ForwarderContract } from '@0x/contracts-exchange-forwarder'; import { blockchainTests, constants, @@ -10,7 +10,7 @@ import { } from '@0x/contracts-test-utils'; import { generatePseudoRandomSalt } from '@0x/order-utils'; import { SignatureType, SignedOrder } from '@0x/types'; -import { AbiEncoder, BigNumber } from '@0x/utils'; +import { AbiEncoder, BigNumber, ExchangeForwarderRevertErrors } from '@0x/utils'; import { deployEth2DaiBridgeAsync } from '../bridges/deploy_eth2dai_bridge'; import { deployUniswapBridgeAsync } from '../bridges/deploy_uniswap_bridge'; @@ -251,7 +251,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => { takerFee: toBaseUnitAmount(0.01), takerFeeAssetData: makerFeeTokenAssetData, }; - const expectedError = new ForwarderRevertErrors.UnsupportedFeeError(makerFeeTokenAssetData); + const expectedError = new ExchangeForwarderRevertErrors.UnsupportedFeeError(makerFeeTokenAssetData); await testFactory.marketSellTestAsync([order], 1.23, { revertError: expectedError }); }); }); @@ -301,7 +301,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => { await testFactory.marketBuyTestAsync(orders, 2.56, { forwarderFeePercentage: 1 }); }); it('should revert if the amount of ETH sent is too low to fill the makerAssetAmount (Eth2Dai)', async () => { - const expectedError = new ForwarderRevertErrors.CompleteBuyFailedError( + const expectedError = new ExchangeForwarderRevertErrors.CompleteBuyFailedError( eth2DaiBridgeOrder.makerAssetAmount.times(0.5), constants.ZERO_AMOUNT, ); @@ -352,7 +352,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => { await testFactory.marketBuyTestAsync(orders, 2.56, { forwarderFeePercentage: 1 }); }); it('should revert if the amount of ETH sent is too low to fill the makerAssetAmount (Uniswap)', async () => { - const expectedError = new ForwarderRevertErrors.CompleteBuyFailedError( + const expectedError = new ExchangeForwarderRevertErrors.CompleteBuyFailedError( uniswapBridgeOrder.makerAssetAmount.times(0.5), constants.ZERO_AMOUNT, ); @@ -370,7 +370,7 @@ blockchainTests.resets('Forwarder <> ERC20Bridge integration tests', env => { takerFee: toBaseUnitAmount(0.01), takerFeeAssetData: makerFeeTokenAssetData, }; - const expectedError = new ForwarderRevertErrors.UnsupportedFeeError(makerFeeTokenAssetData); + const expectedError = new ExchangeForwarderRevertErrors.UnsupportedFeeError(makerFeeTokenAssetData); await testFactory.marketBuyTestAsync([order], 1.23, { revertError: expectedError }); }); }); diff --git a/contracts/staking/test/unit_tests/exchange_test.ts b/contracts/staking/test/unit_tests/exchange_test.ts index df1e8fef28..9e769c8630 100644 --- a/contracts/staking/test/unit_tests/exchange_test.ts +++ b/contracts/staking/test/unit_tests/exchange_test.ts @@ -1,9 +1,8 @@ import { blockchainTests, expect } from '@0x/contracts-test-utils'; import { AuthorizableRevertErrors } from '@0x/contracts-utils'; +import { StakingRevertErrors } from '@0x/utils'; import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; -import { StakingRevertErrors } from '../../src'; - 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 1a6f278559..fd203e891d 100644 --- a/contracts/staking/test/unit_tests/finalizer_test.ts +++ b/contracts/staking/test/unit_tests/finalizer_test.ts @@ -7,11 +7,10 @@ import { Numberish, shortZip, } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, StakingRevertErrors } from '@0x/utils'; import { LogEntry } from 'ethereum-types'; import * as _ from 'lodash'; -import { StakingRevertErrors } from '../../src'; import { constants as stakingConstants } from '../../src/constants'; import { artifacts } from '../artifacts'; 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 1c0ade0fd5..ae020ebc4d 100644 --- a/contracts/staking/test/unit_tests/lib_fixed_math_test.ts +++ b/contracts/staking/test/unit_tests/lib_fixed_math_test.ts @@ -1,9 +1,8 @@ import { blockchainTests, expect, hexRandom, Numberish } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, FixedMathRevertErrors } from '@0x/utils'; import { Decimal } from 'decimal.js'; import * as _ from 'lodash'; -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 3595dc6829..c588472410 100644 --- a/contracts/staking/test/unit_tests/mixin_scheduler_test.ts +++ b/contracts/staking/test/unit_tests/mixin_scheduler_test.ts @@ -1,8 +1,7 @@ import { blockchainTests, constants, expect, verifyEventsFromLogs } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, StakingRevertErrors } from '@0x/utils'; import { LogWithDecodedArgs } from 'ethereum-types'; -import { StakingRevertErrors } from '../../src'; import { constants as stakingConstants } from '../../src/constants'; import { artifacts } from '../artifacts'; diff --git a/contracts/staking/test/unit_tests/protocol_fees_test.ts b/contracts/staking/test/unit_tests/protocol_fees_test.ts index f9e12e4b1b..f268fe6845 100644 --- a/contracts/staking/test/unit_tests/protocol_fees_test.ts +++ b/contracts/staking/test/unit_tests/protocol_fees_test.ts @@ -7,12 +7,10 @@ import { Numberish, randomAddress, } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, StakingRevertErrors } from '@0x/utils'; import { LogEntry } from 'ethereum-types'; import * as _ from 'lodash'; -import { StakingRevertErrors } from '../../src'; - import { artifacts } from '../artifacts'; import { IStakingEventsEvents, diff --git a/contracts/staking/test/unit_tests/stake_test.ts b/contracts/staking/test/unit_tests/stake_test.ts index 3688ac7fa9..a53611c6c1 100644 --- a/contracts/staking/test/unit_tests/stake_test.ts +++ b/contracts/staking/test/unit_tests/stake_test.ts @@ -9,10 +9,9 @@ import { Numberish, shortZip, } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, StakingRevertErrors } from '@0x/utils'; import * as _ from 'lodash'; -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 bc6a19fe67..1c56b18b61 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 { AuthorizableRevertErrors } from '@0x/contracts-utils'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, StakingRevertErrors } from '@0x/utils'; import * as _ from 'lodash'; import { artifacts } from '../artifacts'; @@ -11,7 +11,6 @@ import { TestStakingProxyUnitContract, } from '../wrappers'; -import { StakingRevertErrors } from '../../src'; import { constants as stakingConstants } from '../../src/constants'; blockchainTests.resets('StakingProxy unit tests', env => { diff --git a/contracts/staking/test/unit_tests/zrx_vault_test.ts b/contracts/staking/test/unit_tests/zrx_vault_test.ts index adceab2c84..a693d082e8 100644 --- a/contracts/staking/test/unit_tests/zrx_vault_test.ts +++ b/contracts/staking/test/unit_tests/zrx_vault_test.ts @@ -8,12 +8,10 @@ import { filterLogsToArguments, provider, } from '@0x/contracts-test-utils'; -import { AuthorizableRevertErrors, SafeMathRevertErrors } from '@0x/contracts-utils'; import { RevertReason } from '@0x/types'; -import { BigNumber } from '@0x/utils'; +import { AuthorizableRevertErrors, BigNumber, SafeMathRevertErrors, StakingRevertErrors } from '@0x/utils'; import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; -import { StakingRevertErrors } from '../../src'; import { constants as stakingConstants } from '../../src/constants'; import { artifacts } from '../artifacts';