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

Package detail

@0x/contracts-utils

0xProject2.8kApache-2.04.8.52TypeScript support: included

Smart contract utils of 0x protocol

readme

Contracts utils

This package contains smart contract utilities and libraries that are used throughout the entire codebase of smart contracts. These contracts are all generic and may helpful to use outside of the context of 0x protocol.

Installation

Install

npm install @0x/contracts-utils --save

Contributing

We strongly recommend that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository.

For proposals regarding the 0x protocol's smart contract architecture, message format, or additional functionality, go to the 0x Improvement Proposals (ZEIPs) repository and follow the contribution guidelines provided therein.

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/contracts-utils yarn build

Or continuously rebuild on change:

PKG=@0x/contracts-utils yarn watch

Clean

yarn clean

Lint

yarn lint

Run Tests

yarn test

changelog

CHANGELOG

v4.8.52 - November 16, 2023

* Dependencies updated

v4.8.51 - August 29, 2023

* Dependencies updated

v4.8.50 - August 18, 2023

* Dependencies updated

v4.8.49 - August 9, 2023

* Dependencies updated

v4.8.48 - July 21, 2023

* Dependencies updated

v4.8.47 - July 19, 2023

* Dependencies updated

v4.8.46 - May 10, 2023

* Dependencies updated

v4.8.45 - May 1, 2023

* Dependencies updated

v4.8.44 - April 20, 2023

* Dependencies updated

v4.8.43 - April 17, 2023

* Dependencies updated

v4.8.42 - April 17, 2023

* Dependencies updated

v4.8.41 - April 10, 2023

* Dependencies updated

v4.8.40 - March 10, 2023

* Dependencies updated

v4.8.39 - March 1, 2023

* Dependencies updated

v4.8.38 - February 1, 2023

* Dependencies updated

v4.8.37 - January 30, 2023

* Dependencies updated

v4.8.36 - January 23, 2023

* Dependencies updated

v4.8.35 - December 12, 2022

* Dependencies updated

v4.8.34 - November 23, 2022

* Dependencies updated

v4.8.33 - November 15, 2022

* Dependencies updated

v4.8.32 - November 5, 2022

* Dependencies updated

v4.8.31 - November 2, 2022

* Dependencies updated

v4.8.30 - October 24, 2022

* Dependencies updated

v4.8.29 - October 21, 2022

* Dependencies updated

v4.8.28 - October 13, 2022

* Dependencies updated

v4.8.27 - October 11, 2022

* Dependencies updated

v4.8.26 - October 5, 2022

* Migrate from TSLint to ESLint and fix linting errors (#589)

v4.8.25 - September 21, 2022

* Dependencies updated

v4.8.24 - September 12, 2022

* Dependencies updated

v4.8.23 - September 7, 2022

* Dependencies updated

v4.8.22 - September 2, 2022

* Dependencies updated

v4.8.21 - September 1, 2022

* Dependencies updated

v4.8.20 - August 25, 2022

* Dependencies updated

v4.8.19 - August 25, 2022

* Dependencies updated

v4.8.18 - August 22, 2022

* Dependencies updated

v4.8.17 - August 10, 2022

* Dependencies updated

v4.8.16 - August 9, 2022

* Dependencies updated

v4.8.15 - August 6, 2022

* Dependencies updated

v4.8.14 - July 27, 2022

* Dependencies updated

v4.8.13 - June 14, 2022

* Dependencies updated

v4.8.12 - June 3, 2022

* Dependencies updated

v4.8.11 - May 19, 2022

* Dependencies updated

v4.8.10 - April 22, 2022

* Dependencies updated

v4.8.9 - March 31, 2022

* Dependencies updated

v4.8.8 - March 2, 2022

* Dependencies updated

v4.8.7 - February 22, 2022

* Dependencies updated

v4.8.6 - December 24, 2021

* Dependencies updated

v4.8.5 - December 1, 2021

* Dependencies updated

v4.8.4 - November 16, 2021

* Dependencies updated

v4.8.3 - November 3, 2021

* Dependencies updated

v4.8.2 - October 19, 2021

* Dependencies updated

v4.8.1 - September 15, 2021

* Dependencies updated

v4.8.0 - September 8, 2021

* Added FundRecoveryFeature to the 0x EP (#306)

v4.7.18 - September 1, 2021

* Dependencies updated

v4.7.17 - August 19, 2021

* Dependencies updated

v4.7.16 - August 16, 2021

* Dependencies updated

v4.7.15 - August 11, 2021

* Dependencies updated

v4.7.14 - August 6, 2021

* Dependencies updated

v4.7.13 - June 22, 2021

* Dependencies updated

v4.7.12 - June 11, 2021

* Dependencies updated

v4.7.11 - June 2, 2021

* Dependencies updated

v4.7.10 - May 25, 2021

* Dependencies updated

v4.7.9 - May 21, 2021

* Dependencies updated

v4.7.8 - May 5, 2021

* Dependencies updated

v4.7.7 - April 28, 2021

* Dependencies updated

v4.7.6 - April 1, 2021

* Dependencies updated

v4.7.5 - March 17, 2021

* Dependencies updated

v4.7.4 - February 24, 2021

* Dependencies updated

v4.7.3 - February 10, 2021

* Dependencies updated

v4.7.2 - January 26, 2021

* Dependencies updated

v4.7.1 - January 13, 2021

* Dependencies updated

v4.7.0 - January 4, 2021

* Add `LibSafeMathV06.safeDowncastToUint128()` (#97)
* Add SPDX license identifiers to solidity files (#105)

v4.6.5 - December 23, 2020

* Dependencies updated

v4.6.4 - December 17, 2020

* Dependencies updated

v4.6.3 - December 9, 2020

* Dependencies updated

v4.6.2 - December 7, 2020

* Dependencies updated

v4.6.1 - December 3, 2020

* Dependencies updated

v4.6.0 - November 19, 2020

* Add `uint128` functions to `LibSafeMathV06` (#27)

v4.5.8 - November 13, 2020

* Dependencies updated

v4.5.7 - November 3, 2020

* Dependencies updated

v4.5.6 - November 3, 2020

* Dependencies updated

v4.5.5 - November 2, 2020

* Dependencies updated

v4.5.4 - October 28, 2020

* Dependencies updated

v4.5.3 - October 27, 2020

* Dependencies updated

v4.5.2 - October 21, 2020

* Add Ropsten and Rinkeby addresses to `DeploymentConstants` (#2656)

v4.5.1 - July 15, 2020

* Reorganize `DeploymentConstants` addresses (#2628)

v4.5.0 - June 24, 2020

* Added `GST_ADDRESS` and `GST_COLLECTOR_ADDRESS` (#2523)
* Set GST Collector address in `DeploymentConstants` (#2530)
* Add solidity 0.6 contracts (#2540)
* Add more solidity 0.6 contracts (#2545)
* Add UniswapV2 addresses to `DeploymentConstants` (#2595)
* Update V06 contracts to get around 0.6.9 docstring errors (#2597)

v4.4.3 - March 3, 2020

* Dependencies updated

v4.4.2 - February 27, 2020

* Dependencies updated

v4.4.1 - February 26, 2020

* Dependencies updated

v4.4.0 - February 25, 2020

* Add `D18` library (#2466)

v4.3.1 - February 15, 2020

* Dependencies updated

v4.3.0 - February 8, 2020

* Update Eth2Dai addresses in `DeploymentConstants` (#2474)

v4.2.1 - February 6, 2020

* Dependencies updated

v4.2.0 - February 4, 2020

* Update kovan addresses in `DeploymentConstants` (#2459)
* Export `EvmBytecodeOutputLinkReferences` type. (#2462)

v4.1.0 - January 22, 2020

* Replaced ethers with 0x ABI Encoder for decoding logs. Fixes decoding for arrays/objects. (#2443)

v4.0.3 - January 6, 2020

* Dependencies updated

v4.0.2 - December 17, 2019

* Add `DEV_UTILS_ADDRESS` and `KYBER_ETH_ADDRESS` to `DeploymentConstants`. (#2395)
* Add `DydxBridge` to `DeploymentConstants`. (#2365)

v4.0.1 - December 9, 2019

* Dependencies updated

v4.0.0 - December 2, 2019

* Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils (#2330)
* Introduced new exports AuthorizableRevertErrors, LibAddressArrayRevertErrors, LibBytesRevertErrors, OwnableRevertErrors, ReentrancyGuardRevertErrors and SafeMathRevertErrors (#2321)
* Change ReentrancyGuard implementation to cheaper one (#1699)
* Add LibEIP712 contract (#1753)
* Add `RichErrors` and `mixins/MRichErrors` (#1761)
* Break out types/interaces from `MRichErrors` into `MRichErrorTypes`. (#1790)
* Add LibEIP1271.sol (#1885)
* Updated RichErrors to the library pattern, and implemented RichErrors for all remaining reverts and requires (#1913)
* Added unit tests for all of the internal functions in the package (#2014)
* Updated Ownable to revert when the owner attempts to transfer ownership to the zero address (#2019)
* Add reference functions for `SafeMath` functions. (#2031)
* Throw a `SafeMathError` in `SafeMath._safeDiv()` when denominator is zero. (#2031)
* Create `LibSafeMath` (#2055)
* Rename `_rrevert` to `rrevert` in `LibRichErrors` contract (#2055)
* Compile and export all contracts, artifacts, and wrappers by default (#2055)
* Added LibFractions (#2118)
* Introduce automatic normalization and some zero-value shortcuts in `LibFractions`. (#2155)
* Emit an event in `transferOwnership` (#2253)
* Removed `deepCopyBytes`, `popLast20Bytes`, `readBytesWithLength`, and `writeBytesWithLength` in `LibBytes`. (#2265)
* Replaced `SafeMath` with `LibSafeMath` (#2254)

v3.3.0-beta.4 - December 2, 2019

* Dependencies updated

v3.3.0-beta.3 - November 20, 2019

* Dependencies updated

v3.3.0-beta.2 - November 17, 2019

* Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils (#2330)
* Introduced new exports AuthorizableRevertErrors, LibAddressArrayRevertErrors, LibBytesRevertErrors, OwnableRevertErrors, ReentrancyGuardRevertErrors and SafeMathRevertErrors (#2321)

v3.3.0-beta.1 - November 7, 2019

* Dependencies updated

v3.3.0-beta.0 - October 3, 2019

* Change ReentrancyGuard implementation to cheaper one (#1699)
* Add LibEIP712 contract (#1753)
* Add `RichErrors` and `mixins/MRichErrors` (#1761)
* Break out types/interaces from `MRichErrors` into `MRichErrorTypes`. (#1790)
* Add LibEIP1271.sol (#1885)
* Updated RichErrors to the library pattern, and implemented RichErrors for all remaining reverts and requires (#1913)
* Added unit tests for all of the internal functions in the package (#2014)
* Updated Ownable to revert when the owner attempts to transfer ownership to the zero address (#2019)
* Add reference functions for `SafeMath` functions. (#2031)
* Throw a `SafeMathError` in `SafeMath._safeDiv()` when denominator is zero. (#2031)
* Create `LibSafeMath` (#2055)
* Rename `_rrevert` to `rrevert` in `LibRichErrors` contract (#2055)
* Compile and export all contracts, artifacts, and wrappers by default (#2055)
* Added LibFractions (#2118)
* Introduce automatic normalization and some zero-value shortcuts in `LibFractions`. (#2155)
* Emit an event in `transferOwnership` (#2253)
* Removed `deepCopyBytes`, `popLast20Bytes`, `readBytesWithLength`, and `writeBytesWithLength` in `LibBytes`. (#2265)
* Replaced `SafeMath` with `LibSafeMath` (#2254)

v3.2.4 - September 17, 2019

* Dependencies updated

v3.2.3 - September 3, 2019

* Dependencies updated

v3.2.2 - August 22, 2019

* Dependencies updated

v3.2.1 - August 8, 2019

* Dependencies updated

v3.2.0 - July 31, 2019

* Updated calls to <contract wrapper>.deployFrom0xArtifactAsync to include artifact dependencies. (#1995)
* Added tests for decoding log arguments when artifact dependencies are included/excluded. (#1995)

v3.1.10 - July 24, 2019

* Dependencies updated

v3.1.9 - July 15, 2019

* Dependencies updated

v3.1.8 - July 13, 2019

* Dependencies updated

v3.1.7 - July 13, 2019

* Dependencies updated

v3.1.6 - May 24, 2019

* Dependencies updated

v3.1.5 - May 15, 2019

* Dependencies updated

v3.1.4 - May 14, 2019

* Dependencies updated

v3.1.2 - May 10, 2019

* Dependencies updated

v3.1.1 - April 11, 2019

* Dependencies updated

v3.1.0 - March 21, 2019

* Added `startProviderEngine` to `providerUtils`. Preventing excess block polling (#1695)

v3.0.0 - March 20, 2019

* Optimize loops in LibAddressArray (#1668)
* Upgrade contracts to Solidity 0.5.5 (#1682)
* Added Address.sol with test for whether or not an address is a contract (#1657)
* Add unit tests for `LibAddressArray` (#1712)
* Fix `LibAddressArray.indexOf` returning incorrect index. (#1712)

v2.0.8 - March 1, 2019

* Dependencies updated

v2.0.7 - February 27, 2019

* Dependencies updated

v2.0.6 - February 26, 2019

* Dependencies updated

v2.0.5 - February 25, 2019

* Fix bug in `LibBytes.slice` and `LibBytes.sliceDestructive` (#1604)
* Upgrade contracts to Solidity 0.5.3 (#1604)

v2.0.4 - February 9, 2019

* Dependencies updated

v2.0.3 - February 7, 2019

* Dependencies updated

v2.0.2 - February 7, 2019

* Fake publish to enable pinning

v2.0.1 - February 6, 2019

* Dependencies updated

v2.0.0 - February 5, 2019

* Upgrade the bignumber.js to v8.0.2 (#1517)
* Fix imports in `TestConstants` and `TestLibBytes` to be relative. This way they show up correctly in coverage reports (#1535)
* Add LibAddressArray contract (#1539)
* Do not nest contracts in redundant directories (#1539)
* Rename utils directory to src (#1539)

v1.0.6 - January 17, 2019

* Dependencies updated

v1.0.5 - January 15, 2019

* Dependencies updated

v1.0.4 - January 11, 2019

* Dependencies updated

v1.0.3 - January 9, 2019

* Dependencies updated

v1.0.2 - December 13, 2018

* Dependencies updated