aboutsummaryrefslogtreecommitdiffstats
path: root/contracts/utils
diff options
context:
space:
mode:
Diffstat (limited to 'contracts/utils')
-rw-r--r--contracts/utils/CHANGELOG.json62
-rw-r--r--contracts/utils/CHANGELOG.md12
-rw-r--r--contracts/utils/README.md13
-rw-r--r--contracts/utils/contracts/src/LibAddressArray.sol84
-rw-r--r--contracts/utils/contracts/src/LibBytes.sol (renamed from contracts/utils/contracts/utils/LibBytes/LibBytes.sol)0
-rw-r--r--contracts/utils/contracts/src/Ownable.sol (renamed from contracts/utils/contracts/utils/Ownable/Ownable.sol)2
-rw-r--r--contracts/utils/contracts/src/ReentrancyGuard.sol (renamed from contracts/utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol)0
-rw-r--r--contracts/utils/contracts/src/SafeMath.sol (renamed from contracts/utils/contracts/utils/SafeMath/SafeMath.sol)0
-rw-r--r--contracts/utils/contracts/src/interfaces/IOwnable.sol (renamed from contracts/utils/contracts/utils/Ownable/IOwnable.sol)0
-rw-r--r--contracts/utils/contracts/test/TestConstants.sol (renamed from contracts/utils/contracts/test/TestConstants/TestConstants.sol)4
-rw-r--r--contracts/utils/contracts/test/TestLibBytes.sol (renamed from contracts/utils/contracts/test/TestLibBytes/TestLibBytes.sol)4
-rw-r--r--contracts/utils/package.json39
-rw-r--r--contracts/utils/test/lib_bytes.ts3
-rw-r--r--contracts/utils/test/libs.ts3
14 files changed, 188 insertions, 38 deletions
diff --git a/contracts/utils/CHANGELOG.json b/contracts/utils/CHANGELOG.json
index 50872eb07..94434b803 100644
--- a/contracts/utils/CHANGELOG.json
+++ b/contracts/utils/CHANGELOG.json
@@ -1,5 +1,67 @@
[
{
+ "version": "3.0.0",
+ "changes": [
+ {
+ "note": "Add LibAddressArray contract",
+ "pr": 1539
+ },
+ {
+ "note": "Do not nest contracts in redundant directories",
+ "pr": 1539
+ },
+ {
+ "note": "Rename utils directory to src",
+ "pr": 1539
+ }
+ ]
+ },
+ {
+ "version": "2.0.1",
+ "changes": [
+ {
+ "note": "Fix imports in `TestConstants` and `TestLibBytes` to be relative. This way they show up correctly in coverage reports",
+ "pr": 1535
+ }
+ ]
+ },
+ {
+ "version": "2.0.0",
+ "changes": [
+ {
+ "note": "Upgrade the bignumber.js to v8.0.2",
+ "pr": 1517
+ }
+ ]
+ },
+ {
+ "timestamp": 1547747677,
+ "version": "1.0.6",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1547561734,
+ "version": "1.0.5",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1547225310,
+ "version": "1.0.4",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
"timestamp": 1547040760,
"version": "1.0.3",
"changes": [
diff --git a/contracts/utils/CHANGELOG.md b/contracts/utils/CHANGELOG.md
index 4732f1746..59d0804da 100644
--- a/contracts/utils/CHANGELOG.md
+++ b/contracts/utils/CHANGELOG.md
@@ -5,6 +5,18 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## 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
diff --git a/contracts/utils/README.md b/contracts/utils/README.md
index e7c7b49ff..5c69971b6 100644
--- a/contracts/utils/README.md
+++ b/contracts/utils/README.md
@@ -1,15 +1,14 @@
## Contracts utils
-Smart contracts utils used in the 0x protocol.
+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.
-## Usage
+## Installation
-Contracts can be found in the [contracts](./contracts) directory. The contents of this directory are broken down into the following subdirectories:
+**Install**
-* [utils](./contracts/utils)
- * This directory contains libraries and utils.
-* [test](./contracts/test)
- * This directory contains mocks and other contracts that are used solely for testing contracts within the other directories.
+```bash
+npm install @0x/contracts-utils --save
+```
## Contributing
diff --git a/contracts/utils/contracts/src/LibAddressArray.sol b/contracts/utils/contracts/src/LibAddressArray.sol
new file mode 100644
index 000000000..892c486f1
--- /dev/null
+++ b/contracts/utils/contracts/src/LibAddressArray.sol
@@ -0,0 +1,84 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity ^0.4.24;
+
+import "./LibBytes.sol";
+
+
+library LibAddressArray {
+
+ /// @dev Append a new address to an array of addresses.
+ /// The `addressArray` may need to be reallocated to make space
+ /// for the new address. Because of this we return the resulting
+ /// memory location of `addressArray`.
+ /// @param addressToAppend Address to append.
+ /// @return Array of addresses: [... addressArray, addressToAppend]
+ function append(address[] memory addressArray, address addressToAppend)
+ internal pure
+ returns (address[])
+ {
+ // Get stats on address array and free memory
+ uint256 freeMemPtr = 0;
+ uint256 addressArrayBeginPtr = 0;
+ uint256 addressArrayEndPtr = 0;
+ uint256 addressArrayLength = addressArray.length;
+ uint256 addressArrayMemSizeInBytes = 32 + (32 * addressArrayLength);
+ assembly {
+ freeMemPtr := mload(0x40)
+ addressArrayBeginPtr := addressArray
+ addressArrayEndPtr := add(addressArray, addressArrayMemSizeInBytes)
+ }
+
+ // Cases for `freeMemPtr`:
+ // `freeMemPtr` == `addressArrayEndPtr`: Nothing occupies memory after `addressArray`
+ // `freeMemPtr` > `addressArrayEndPtr`: Some value occupies memory after `addressArray`
+ // `freeMemPtr` < `addressArrayEndPtr`: Memory has not been managed properly.
+ require(
+ freeMemPtr >= addressArrayEndPtr,
+ "INVALID_FREE_MEMORY_PTR"
+ );
+
+ // If free memory begins at the end of `addressArray`
+ // then we can append `addressToAppend` directly.
+ // Otherwise, we must copy the array to free memory
+ // before appending new values to it.
+ if (freeMemPtr > addressArrayEndPtr) {
+ LibBytes.memCopy(freeMemPtr, addressArrayBeginPtr, addressArrayMemSizeInBytes);
+ assembly {
+ addressArray := freeMemPtr
+ addressArrayBeginPtr := addressArray
+ }
+ }
+
+ // Append `addressToAppend`
+ addressArrayLength += 1;
+ addressArrayMemSizeInBytes += 32;
+ addressArrayEndPtr = addressArrayBeginPtr + addressArrayMemSizeInBytes;
+ freeMemPtr = addressArrayEndPtr;
+ assembly {
+ // Store new array length
+ mstore(addressArray, addressArrayLength)
+
+ // Update `freeMemPtr`
+ mstore(0x40, freeMemPtr)
+ }
+ addressArray[addressArrayLength - 1] = addressToAppend;
+ return addressArray;
+ }
+}
diff --git a/contracts/utils/contracts/utils/LibBytes/LibBytes.sol b/contracts/utils/contracts/src/LibBytes.sol
index 4ee6228d5..4ee6228d5 100644
--- a/contracts/utils/contracts/utils/LibBytes/LibBytes.sol
+++ b/contracts/utils/contracts/src/LibBytes.sol
diff --git a/contracts/utils/contracts/utils/Ownable/Ownable.sol b/contracts/utils/contracts/src/Ownable.sol
index aa74a72d2..f67f241a4 100644
--- a/contracts/utils/contracts/utils/Ownable/Ownable.sol
+++ b/contracts/utils/contracts/src/Ownable.sol
@@ -1,6 +1,6 @@
pragma solidity ^0.4.24;
-import "./IOwnable.sol";
+import "./interfaces/IOwnable.sol";
contract Ownable is
diff --git a/contracts/utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol b/contracts/utils/contracts/src/ReentrancyGuard.sol
index 1a02c88a4..1a02c88a4 100644
--- a/contracts/utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol
+++ b/contracts/utils/contracts/src/ReentrancyGuard.sol
diff --git a/contracts/utils/contracts/utils/SafeMath/SafeMath.sol b/contracts/utils/contracts/src/SafeMath.sol
index d7a4a603e..d7a4a603e 100644
--- a/contracts/utils/contracts/utils/SafeMath/SafeMath.sol
+++ b/contracts/utils/contracts/src/SafeMath.sol
diff --git a/contracts/utils/contracts/utils/Ownable/IOwnable.sol b/contracts/utils/contracts/src/interfaces/IOwnable.sol
index c0cbfddfd..c0cbfddfd 100644
--- a/contracts/utils/contracts/utils/Ownable/IOwnable.sol
+++ b/contracts/utils/contracts/src/interfaces/IOwnable.sol
diff --git a/contracts/utils/contracts/test/TestConstants/TestConstants.sol b/contracts/utils/contracts/test/TestConstants.sol
index 3c852173b..bf98bafef 100644
--- a/contracts/utils/contracts/test/TestConstants/TestConstants.sol
+++ b/contracts/utils/contracts/test/TestConstants.sol
@@ -16,9 +16,9 @@
*/
-pragma solidity 0.4.24;
+pragma solidity ^0.4.24;
-import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol";
+import "../src/LibBytes.sol";
// solhint-disable max-line-length
diff --git a/contracts/utils/contracts/test/TestLibBytes/TestLibBytes.sol b/contracts/utils/contracts/test/TestLibBytes.sol
index 444a3e717..cd6b1456d 100644
--- a/contracts/utils/contracts/test/TestLibBytes/TestLibBytes.sol
+++ b/contracts/utils/contracts/test/TestLibBytes.sol
@@ -16,9 +16,9 @@
*/
-pragma solidity 0.4.24;
+pragma solidity ^0.4.24;
-import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol";
+import "../src/LibBytes.sol";
contract TestLibBytes {
diff --git a/contracts/utils/package.json b/contracts/utils/package.json
index 732556f34..33d94cc33 100644
--- a/contracts/utils/package.json
+++ b/contracts/utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@0x/contracts-utils",
- "version": "1.0.3",
+ "version": "3.0.0",
"engines": {
"node": ">=6.12"
},
@@ -44,40 +44,35 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/utils/README.md",
"devDependencies": {
- "@0x/abi-gen": "^1.0.20",
- "@0x/contracts-test-utils": "^1.0.3",
- "@0x/dev-utils": "^1.0.22",
- "@0x/sol-compiler": "^2.0.0",
- "@0x/subproviders": "^2.1.9",
- "@0x/tslint-config": "^2.0.0",
- "@types/bn.js": "^4.11.0",
+ "@0x/abi-gen": "^1.0.22",
+ "@0x/contracts-test-utils": "^2.0.1",
+ "@0x/dev-utils": "^1.0.24",
+ "@0x/sol-compiler": "^2.0.2",
+ "@0x/tslint-config": "^2.0.2",
"@types/lodash": "4.14.104",
"@types/node": "*",
- "@types/yargs": "^10.0.0",
- "bn.js": "^4.11.8",
+ "@types/bn.js": "^4.11.0",
"chai": "^4.0.1",
"chai-as-promised": "^7.1.0",
- "chai-bignumber": "^2.0.1",
+ "chai-bignumber": "^3.0.0",
"dirty-chai": "^2.0.1",
- "ethereumjs-abi": "0.6.5",
"make-promises-safe": "^1.1.0",
"mocha": "^4.1.0",
"npm-run-all": "^4.1.2",
"shx": "^0.2.2",
"solhint": "^1.4.1",
"tslint": "5.11.0",
- "typescript": "3.0.1",
- "yargs": "^10.0.3"
+ "typescript": "3.0.1"
},
"dependencies": {
- "@0x/base-contract": "^3.0.11",
- "@0x/contracts-multisig": "^1.0.3",
- "@0x/order-utils": "^3.1.0",
- "@0x/types": "^1.5.0",
- "@0x/typescript-typings": "^3.0.6",
- "@0x/utils": "^2.1.1",
- "@0x/web3-wrapper": "^3.2.2",
- "ethereum-types": "^1.1.4",
+ "@0x/base-contract": "^3.0.13",
+ "@0x/order-utils": "^3.1.2",
+ "@0x/types": "^1.5.2",
+ "@0x/typescript-typings": "^3.0.8",
+ "@0x/utils": "^3.0.1",
+ "@0x/web3-wrapper": "^3.2.4",
+ "bn.js": "^4.11.8",
+ "ethereum-types": "^1.1.6",
"ethereumjs-util": "^5.1.1",
"lodash": "^4.17.5"
},
diff --git a/contracts/utils/test/lib_bytes.ts b/contracts/utils/test/lib_bytes.ts
index 6fb859c67..daad28729 100644
--- a/contracts/utils/test/lib_bytes.ts
+++ b/contracts/utils/test/lib_bytes.ts
@@ -16,8 +16,7 @@ import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
-import { TestLibBytesContract } from '../generated-wrappers/test_lib_bytes';
-import { artifacts } from '../src';
+import { artifacts, TestLibBytesContract } from '../src';
chaiSetup.configure();
const expect = chai.expect;
diff --git a/contracts/utils/test/libs.ts b/contracts/utils/test/libs.ts
index 81596b2e4..77dc6e2ba 100644
--- a/contracts/utils/test/libs.ts
+++ b/contracts/utils/test/libs.ts
@@ -2,8 +2,7 @@ import { chaiSetup, provider, txDefaults, web3Wrapper } from '@0x/contracts-test
import { BlockchainLifecycle } from '@0x/dev-utils';
import * as chai from 'chai';
-import { TestConstantsContract } from '../generated-wrappers/test_constants';
-import { artifacts } from '../src';
+import { artifacts, TestConstantsContract } from '../src';
chaiSetup.configure();
const expect = chai.expect;