Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@0x/order-utils

0xProject5.6kApache-2.010.4.28TypeScript support: included

0x order utils

readme

@0x/order-utils

0x order-related utilities for those developing on top of 0x protocol.

Read the Documentation.

Installation

yarn add @0x/order-utils

If your project is in TypeScript, add the following to your tsconfig.json:

"compilerOptions": {
    "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"],
}

Contributing

We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.

Please read our contribution guidelines before getting started.

Install dependencies

If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:

yarn config set workspaces-experimental true

Then install dependencies

yarn install

Build

To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory:

PKG=@0x/order-utils yarn build

Or continuously rebuild on change:

PKG=@0x/order-utils yarn watch

Clean

yarn clean

Lint

yarn lint

changelog

CHANGELOG

v10.4.28 - August 11, 2021

* Dependencies updated

v10.4.27 - August 6, 2021

* Dependencies updated

v10.4.26 - June 22, 2021

* Dependencies updated

v10.4.25 - June 11, 2021

* Dependencies updated

v10.4.24 - June 2, 2021

* Dependencies updated

v10.4.23 - May 25, 2021

* Dependencies updated

v10.4.22 - May 21, 2021

* Dependencies updated

v10.4.21 - May 5, 2021

* Dependencies updated

v10.4.20 - April 28, 2021

* Dependencies updated

v10.4.19 - April 1, 2021

* Dependencies updated

v10.4.18 - March 17, 2021

* Dependencies updated

v10.4.17 - February 24, 2021

* Dependencies updated

v10.4.16 - February 10, 2021

* Dependencies updated

v10.4.15 - January 26, 2021

* Dependencies updated

v10.4.14 - January 13, 2021

* Dependencies updated

v10.4.13 - January 4, 2021

* Dependencies updated

v10.4.12 - December 23, 2020

* Dependencies updated

v10.4.11 - December 17, 2020

* Dependencies updated

v10.4.10 - December 9, 2020

* Dependencies updated

v10.4.9 - December 7, 2020

* Dependencies updated

v10.4.8 - December 3, 2020

* Dependencies updated

v10.4.7 - November 19, 2020

* Dependencies updated

v10.4.6 - November 13, 2020

* Dependencies updated

v10.4.5 - November 3, 2020

* Dependencies updated

v10.4.4 - November 3, 2020

* Dependencies updated

v10.4.3 - November 2, 2020

* Dependencies updated

v10.4.2 - October 28, 2020

* Dependencies updated

v10.4.1 - October 27, 2020

* Dependencies updated

v10.4.0 - October 21, 2020

* Add gitpkg. (#2649)
* Fix `decodeAffiliateFeeTransformerData` (#2658)
* Add `refundReceiver` field to `FillQuoteTransformer.TransformData`. (#2657)
* Add `findTransformerNonce()` and `getTransformerAddress()` functions. (#2657)
* Fix EP signature utils schema assertion. (#2657)
* Add `rfqtTakerAddress` to `FillQuoteTransformerData` (#2692)

v10.3.0 - July 15, 2020

* Add ERC20 Transformer utils and export useful constants. (#2604)
* Add `getOrderHash()`, `getExchangeTransactionHash()`, `getExchangeProxyTransactionHash()` (#2610)

v10.2.5 - June 24, 2020

* Dependencies updated

v10.2.4 - March 3, 2020

* Dependencies updated

v10.2.3 - February 27, 2020

* Dependencies updated

v10.2.2 - February 25, 2020

* Dependencies updated

v10.2.1 - February 15, 2020

* Dependencies updated

v10.2.0 - February 8, 2020

* Remove use of ambient `DevUtils` instances. (#2462)
* Make hash computing tooling non-async again. (#2462)
* Add `transactionHashUtils`. (#2462)

v10.1.3 - February 6, 2020

* Dependencies updated

v10.1.2 - February 4, 2020

* Dependencies updated

v10.1.1 - January 22, 2020

* Dependencies updated

v10.1.0 - January 6, 2020

* Export `isERC20AssetData`, `isERC20BridgeAssetData` and other equivalents. (#2421)

v10.0.1 - December 17, 2019

* Dependencies updated

v10.0.0 - December 9, 2019

* Removed from assetDataUtils: individual decoding functions and assert functions (#2388)
* Add ERC20Bridge support to assetDataUtils (#2388)

v9.0.0 - December 2, 2019

* [Breaking] Removed `OrderStateUtils`, `OrderValidationUtils`, `ExchangeTransferSimulator` and all abstract and store classes. For order validation, please use the `DevUtils` contract wrapper method `getOrderRelevantState`|`getOrderRelevantStates` (#2324)
* Removed exports CoordinatorRevertErrors, ExchangeRevertErrors, ForwarderRevertErrors, LibMathRevertErrors, orderHashUtils, orderParsingUtils, StakingRevertErrors and transactionHashUtils (#2321)
* Removed many functions from export signatureUtils (#2321)
* Removed function isValidOrderHash from export orderHashUtils (#2321)
* Remove `TransferFailedError` from `ForwarderRevertErrors`. (#2309)
* All references to network ID have been removed, and references to chain ID have been introduced instead (#2313)
* Add `chainId` `OrderValidationUtils`, `OrderFactory` (#1742)
* Update tools to use new `Order` and `ZeroExTransaction` structure (#1742)
* Update domain schema for Exchange and Coordinator (#1742)
* Add Exchange `RevertError` types to `ExchangeRevertErrors` (#1761)
* Add `SignatureOrderValidatorError` type to `ExchangeRevertErrors` (#1774)
* Add `SignatureWalletOrderValidatorError` type to `ExchangeRevertErrors` (#1774)
* Reorder parameters of some `RevertError` types to match smart contracts. (#1790)
* Use arbitrary fee tokens instead of ZRX (ZEIP-28) for tools needed by contracts packages. (#1819)
* Update `RevertError` types for new base constructor (#1819)
* Add `Expired` TransactionErrorCode (#1832)
* Add `expirationTimeSeconds` to `ZeroExTransaction` parameters used for hashing (#1832)
* Add `validator` field to `SignatureValidatorError` `RevertError` types. (#1885)
* Remove unused `RevertError` types. (#1885)
* Add `ExchangeRevertErrors.SignatureErrorCode.InvalidSigner`. (#2042)
* Add `takerAssetFillAmount` field to `IncompleteFillError` type (#2075)
* Update `IncompleteFillError` to take an `errorCode`, `expectedAssetFillAmount`, and `actualAssetFillAmount` fields. (#2075)
* Add EIP712 types for Staking (#1910)
* Add `InvalidCobbDouglasAlphaError` `RevertError` type to `StakingRevertErrors` (#2109)
* Rename `OperatorShareMustBeBetween0And100Error` `RevertError` type to `InvalidPoolOperatorShareError`. (#2109)
* Add `TransactionGasPriceError` and `TransactionInvalidContextError` to error registry. (#2109)
* Add `EthVaultNotSetError, `RewardVaultNotSetError`, and `InvalidStakeStatusError` to error registry. (#2118)
* Add `InvalidStakeStatusError` to error registry. (#2126)
* Add `InitializationError`, `InvalidParamValue` to `StakingRevertErrors`. (#2131)
* Add `CumulativeRewardIntervalError`. (#2154)
* Remove `validateOrderFillableOrThrowAsync`, `simpleValidateOrderFillableOrThrowAsync`, `validateMakerTransferThrowIfInvalidAsync` (#2181)
* Add `PreviousEpochNotFinalizedError` to `StakingRevertErrors`. (#2155)
* Add `InvalidMinimumPoolStake` to `StakingRevertErrors.InvalidParamValueErrorCode`. (#2155)
* Renamed `OnlyCallableByPoolOperatorOrMakerError` to `OnlyCallableByPoolOperatorError`. (#2250)
* Removed protocol fee != 0 error. (#2278)

v8.5.0-beta.4 - December 2, 2019

* Dependencies updated

v8.5.0-beta.3 - November 20, 2019

* Dependencies updated

v8.5.0-beta.2 - November 17, 2019

* [Breaking] Removed `OrderStateUtils`, `OrderValidationUtils`, `ExchangeTransferSimulator` and all abstract and store classes. For order validation, please use the `DevUtils` contract wrapper method `getOrderRelevantState`|`getOrderRelevantStates` (#2324)
* Removed exports CoordinatorRevertErrors, ExchangeRevertErrors, ForwarderRevertErrors, LibMathRevertErrors, orderHashUtils, orderParsingUtils, StakingRevertErrors and transactionHashUtils (#2321)
* Removed many functions from export signatureUtils (#2321)
* Removed function isValidOrderHash from export orderHashUtils (#2321)

v8.5.0-beta.1 - November 7, 2019

* Remove `TransferFailedError` from `ForwarderRevertErrors`. (#2309)
* All references to network ID have been removed, and references to chain ID have been introduced instead (#2313)

v8.5.0-beta.0 - October 3, 2019

* Add `chainId` `OrderValidationUtils`, `OrderFactory` (#1742)
* Update tools to use new `Order` and `ZeroExTransaction` structure (#1742)
* Update domain schema for Exchange and Coordinator (#1742)
* Add Exchange `RevertError` types to `ExchangeRevertErrors` (#1761)
* Add `SignatureOrderValidatorError` type to `ExchangeRevertErrors` (#1774)
* Add `SignatureWalletOrderValidatorError` type to `ExchangeRevertErrors` (#1774)
* Reorder parameters of some `RevertError` types to match smart contracts. (#1790)
* Use arbitrary fee tokens instead of ZRX (ZEIP-28) for tools needed by contracts packages. (#1819)
* Update `RevertError` types for new base constructor (#1819)
* Add `Expired` TransactionErrorCode (#1832)
* Add `expirationTimeSeconds` to `ZeroExTransaction` parameters used for hashing (#1832)
* Add `validator` field to `SignatureValidatorError` `RevertError` types. (#1885)
* Remove unused `RevertError` types. (#1885)
* Add `ExchangeRevertErrors.SignatureErrorCode.InvalidSigner`. (#2042)
* Add `takerAssetFillAmount` field to `IncompleteFillError` type (#2075)
* Update `IncompleteFillError` to take an `errorCode`, `expectedAssetFillAmount`, and `actualAssetFillAmount` fields. (#2075)
* Add EIP712 types for Staking (#1910)
* Add `InvalidCobbDouglasAlphaError` `RevertError` type to `StakingRevertErrors` (#2109)
* Rename `OperatorShareMustBeBetween0And100Error` `RevertError` type to `InvalidPoolOperatorShareError`. (#2109)
* Add `TransactionGasPriceError` and `TransactionInvalidContextError` to error registry. (#2109)
* Add `EthVaultNotSetError, `RewardVaultNotSetError`, and `InvalidStakeStatusError` to error registry. (#2118)
* Add `InvalidStakeStatusError` to error registry. (#2126)
* Add `InitializationError`, `InvalidParamValue` to `StakingRevertErrors`. (#2131)
* Add `CumulativeRewardIntervalError`. (#2154)
* Remove `validateOrderFillableOrThrowAsync`, `simpleValidateOrderFillableOrThrowAsync`, `validateMakerTransferThrowIfInvalidAsync` (#2181)
* Add `PreviousEpochNotFinalizedError` to `StakingRevertErrors`. (#2155)
* Add `InvalidMinimumPoolStake` to `StakingRevertErrors.InvalidParamValueErrorCode`. (#2155)
* Renamed `OnlyCallableByPoolOperatorOrMakerError` to `OnlyCallableByPoolOperatorError`. (#2250)
* Removed protocol fee != 0 error. (#2278)

v8.4.0 - September 17, 2019

* Implement `simpleValidateOrderFillableOrThrowAsync` (#2096)

v8.3.1 - September 3, 2019

* Dependencies updated

v8.3.0 - August 22, 2019

* Fix isValidValidatorSignatureAsync, allow to pass exchangeAddress to isValidSignatureAsync. (#2017)
* Fix `Wallet` and `Validator` signature validation (#2078)

v8.2.5 - August 8, 2019

* Dependencies updated

v8.2.4 - July 31, 2019

* Updated calls to <contract wrapper>.deploy0xArtifactAsync to include log decode dependencies. (#1995)

v8.2.3 - July 24, 2019

* Ensure `assetData` is word aligned (#1964)

v8.2.2 - July 15, 2019

* Dependencies updated

v8.2.1 - July 13, 2019

* Dependencies updated

v8.2.0 - July 13, 2019

* Add support for encoding/decoding StaticCallProxy assetData (#1863)
* Add support for marketSell utils (#1914)
* Add support for encoding/decoding DutchAuction assetData (#1943)
* Added `validateMakerTransferThrowIfInvalidAsync` to OrderValidationUtils (#1937)

v8.1.1 - May 24, 2019

* Dependencies updated

v8.1.0 - May 15, 2019

* Add `ecSignTransactionAsync` (#1817)

v8.0.2 - May 14, 2019

* Dependencies updated

v8.0.0 - May 10, 2019

* Renamed `OrderError` to `TypedDataError` (#1792)

v7.2.0 - April 11, 2019

* Added `orderCalculationUtils` (#1714)

v7.1.1 - March 21, 2019

* Dependencies updated

v7.1.0 - March 20, 2019

* Add Coordinator EIP712 constants (#1705)
* Added encoding/decoding for ERC1155 asset data (#1661)

v7.0.2 - March 1, 2019

* Dependencies updated

v7.0.1 - February 26, 2019

* Dependencies updated

v7.0.0 - February 25, 2019

* Add support for EIP1193 providers & Web3.js providers >= 1.0-beta.38 (#1627)
* Update provider params to type SupportedProvider which outlines all supported providers (#1627)

v6.1.0 - February 9, 2019

* Updated implementation of `generatePseudoRandomSalt` to use generator from @0x/utils (#1569)

v6.0.1 - February 7, 2019

* Dependencies updated

v6.0.0 - February 7, 2019

* undefined

v5.0.0 - February 6, 2019

* Add `transactionHashUtils` (#1576)
* Refactor `eip712Utils` to allow custom domain params (#1576)
* Export constant EIP712 params (#1576)

v4.0.0 - February 5, 2019

* Upgrade the bignumber.js to v8.0.2 (#1517)
* Fix preSigned `isSignatureValidAsync` check (#1580)

v3.1.2 - January 15, 2019

* Dependencies updated

v3.1.1 - January 11, 2019

* Dependencies updated

v3.1.0 - January 9, 2019

* Use new ABI encoder, add encoding/decoding logic for MultiAsset assetData, and add information to return values in orderStateUtils (#1363)

v3.0.7 - December 13, 2018

* Dependencies updated

v3.0.6 - December 11, 2018

* Fix bug in wallet signature type verification (#1414)

v3.0.5 - December 10, 2018

* Dependencies updated

v3.0.4 - November 28, 2018

* Dependencies updated

v3.0.3 - November 21, 2018

* Dependencies updated

v3.0.2 - November 14, 2018

* Dependencies updated

v3.0.1 - November 13, 2018

* Dependencies updated

v3.0.0 - November 12, 2018

* Add signature validation, regular cancellation and `cancelledUpTo` checks to `validateOrderFillableOrThrowAsync` (#1235)
* Improved the errors thrown by `validateOrderFillableOrThrowAsync` by making them more descriptive (#1235)
* Throw previously swallowed network errors when calling `validateOrderFillableOrThrowAsync` (see issue: #1218) (#1235)
* Modified the `AbstractOrderFilledCancelledFetcher` interface slightly such that `isOrderCancelledAsync` accepts a `signedOrder` instead of an `orderHash` param (#1235)

v2.0.1 - November 9, 2018

* Dependencies updated

v2.0.0 - October 18, 2018

* Added `ecSignOrderAsync` to first sign an order using `eth_signTypedData` and fallback to `eth_sign`. (#1102)
* Added `ecSignTypedDataOrderAsync` to sign an order exclusively using `eth_signTypedData`. (#1102)
* Rename `ecSignOrderHashAsync` to `ecSignHashAsync` removing `SignerType` parameter. (#1102)
* Use `AssetData` union type for function return values. (#1131)

v1.0.7 - October 4, 2018

* Dependencies updated

v1.0.6 - September 28, 2018

* Add signerAddress normalization to `isValidECSignature` to avoid `invalid address recovery` error if caller supplies a checksummed address (#1096)

v1.0.5 - September 25, 2018

* Dependencies updated

v1.0.4 - September 25, 2018

* Dependencies updated

v1.0.3 - September 21, 2018

* Dependencies updated

v1.0.2 - September 19, 2018

* Drastically reduce the bundle size by removing unused parts of included contract artifacts.

v1.0.1 - September 5, 2018

* Export `orderParsingUtils` (#1044)

v1.0.1-rc.6 - August 27, 2018

* Fix missing `BlockParamLiteral` type import issue

v1.0.1-rc.5 - Invalid date

* Remove Caller and Trezor SignatureTypes (#1015)

v1.0.1-rc.4 - August 24, 2018

* Remove rounding error being thrown when maker amount is very small (#959)
* Added rateUtils and sortingUtils (#953)
* Update marketUtils api such that all optional parameters are bundled into one optional param and more defaults are provided (#954)
* Instead of exporting signature util methods individually, they are now exported as `signatureUtils` (#924)
* Export types: `SignedOrder`, `Order`, `OrderRelevantState`, `OrderState`, `ECSignature`, `ERC20AssetData`, `ERC721AssetData`, `AssetProxyId`, `SignerType`, `SignatureType`, `OrderStateValid`, `OrderStateInvalid`, `ExchangeContractErrs`, `TradeSide`, `TransferType`, `FindFeeOrdersThatCoverFeesForTargetOrdersOpts`, `FindOrdersThatCoverMakerAssetFillAmountOpts`, `FeeOrdersAndRemainingFeeAmount`, `OrdersAndRemainingFillAmount`, `Provider`, `JSONRPCRequestPayload`, `JSONRPCErrorCallback` and `JSONRPCResponsePayload` (#924)
* Rename `resultOrders` to `resultFeeOrders` for object returned by `findFeeOrdersThatCoverFeesForTargetOrders` in `marketUtils` api (#997)
* Make `sortFeeOrdersByFeeAdjustedRate` in `sortingUtils` generic (#997)
* Update `findFeeOrdersThatCoverFeesForTargetOrders` to round the the nearest integer when calculating required fees (#997)

v1.0.1-rc.3 - August 14, 2018

* Update ecSignOrderHashAsync to return signature string with signature type byte. Removes messagePrefixOpts. (#914)
* Added a synchronous `createOrder` method in `orderFactory`, updated public interfaces to support some optional parameters (#936)
* Added marketUtils (#937)
* Dependencies updated

v1.0.1-rc.2 - July 26, 2018

* Dependencies updated

v1.0.1-rc.1 - July 26, 2018

* Dependencies updated

v1.0.0 - July 23, 2018

* Dependencies updated

v1.0.0-rc.2 - July 23, 2018

* Upgrade ethereumjs-abi dep including a fix so that addresses starting with 0 are properly decoded by `decodeERC20AssetData`

v1.0.0-rc.1 - July 19, 2018

* Refactor to work with V2 of 0x protocol (#636)
* Export parseECSignature method (#684)
* Handle Typed Arrays when hashing data (#894)

v0.0.9 - July 18, 2018

* Dependencies updated

v0.0.8 - July 9, 2018

* Dependencies updated

v0.0.7 - June 19, 2018

* Dependencies updated

v0.0.6 - May 29, 2018

* Dependencies updated

v0.0.5 - May 22, 2018

* Add orderStateUtils, a module for computing order state needed to decide if an order is still valid

v0.0.4 - May 4, 2018

* Dependencies updated

v0.0.3 - May 4, 2018

* Dependencies updated

v0.0.2 - May 4, 2018

* Dependencies updated