diff options
Diffstat (limited to 'contracts')
47 files changed, 330 insertions, 55 deletions
diff --git a/contracts/core/compiler.json b/contracts/core/compiler.json index 1ffc26b05..8d9732794 100644 --- a/contracts/core/compiler.json +++ b/contracts/core/compiler.json @@ -44,8 +44,6 @@ "ReentrantERC20Token", "TestAssetProxyOwner", "TestAssetProxyDispatcher", - "TestConstants", - "TestLibBytes", "TestLibs", "TestExchangeInternals", "TestSignatureValidator", diff --git a/contracts/core/contracts/examples/Wallet/Wallet.sol b/contracts/core/contracts/examples/Wallet/Wallet.sol index b75021a31..3738be841 100644 --- a/contracts/core/contracts/examples/Wallet/Wallet.sol +++ b/contracts/core/contracts/examples/Wallet/Wallet.sol @@ -19,7 +19,7 @@ pragma solidity 0.4.24; import "../../protocol/Exchange/interfaces/IWallet.sol"; -import "../../utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; contract Wallet is diff --git a/contracts/core/contracts/examples/Whitelist/Whitelist.sol b/contracts/core/contracts/examples/Whitelist/Whitelist.sol index e4e25038c..61c21c095 100644 --- a/contracts/core/contracts/examples/Whitelist/Whitelist.sol +++ b/contracts/core/contracts/examples/Whitelist/Whitelist.sol @@ -21,7 +21,7 @@ pragma experimental ABIEncoderV2; import "../../protocol/Exchange/interfaces/IExchange.sol"; import "../../protocol/Exchange/libs/LibOrder.sol"; -import "../../utils/Ownable/Ownable.sol"; +import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; contract Whitelist is diff --git a/contracts/core/contracts/extensions/DutchAuction/DutchAuction.sol b/contracts/core/contracts/extensions/DutchAuction/DutchAuction.sol index abe8309cf..dfd4c46dc 100644 --- a/contracts/core/contracts/extensions/DutchAuction/DutchAuction.sol +++ b/contracts/core/contracts/extensions/DutchAuction/DutchAuction.sol @@ -22,8 +22,8 @@ pragma experimental ABIEncoderV2; import "../../protocol/Exchange/interfaces/IExchange.sol"; import "../../protocol/Exchange/libs/LibOrder.sol"; import "../../tokens/ERC20Token/IERC20Token.sol"; -import "../../utils/LibBytes/LibBytes.sol"; -import "../../utils/SafeMath/SafeMath.sol"; +import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-utils/contracts/utils/SafeMath/SafeMath.sol"; contract DutchAuction is diff --git a/contracts/core/contracts/extensions/Forwarder/MixinAssets.sol b/contracts/core/contracts/extensions/Forwarder/MixinAssets.sol index 43efb5ff3..5f5f3456d 100644 --- a/contracts/core/contracts/extensions/Forwarder/MixinAssets.sol +++ b/contracts/core/contracts/extensions/Forwarder/MixinAssets.sol @@ -18,8 +18,8 @@ pragma solidity 0.4.24; -import "../../utils/LibBytes/LibBytes.sol"; -import "../../utils/Ownable/Ownable.sol"; +import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; import "../../tokens/ERC20Token/IERC20Token.sol"; import "../../tokens/ERC721Token/IERC721Token.sol"; import "./libs/LibConstants.sol"; diff --git a/contracts/core/contracts/extensions/Forwarder/MixinForwarderCore.sol b/contracts/core/contracts/extensions/Forwarder/MixinForwarderCore.sol index 54487f726..a5dd99225 100644 --- a/contracts/core/contracts/extensions/Forwarder/MixinForwarderCore.sol +++ b/contracts/core/contracts/extensions/Forwarder/MixinForwarderCore.sol @@ -24,7 +24,7 @@ import "./mixins/MWeth.sol"; import "./mixins/MAssets.sol"; import "./mixins/MExchangeWrapper.sol"; import "./interfaces/IForwarderCore.sol"; -import "../../utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; import "../../protocol/Exchange/libs/LibOrder.sol"; import "../../protocol/Exchange/libs/LibFillResults.sol"; import "../../protocol/Exchange/libs/LibMath.sol"; diff --git a/contracts/core/contracts/extensions/Forwarder/libs/LibConstants.sol b/contracts/core/contracts/extensions/Forwarder/libs/LibConstants.sol index 704e42ce3..0f98ae595 100644 --- a/contracts/core/contracts/extensions/Forwarder/libs/LibConstants.sol +++ b/contracts/core/contracts/extensions/Forwarder/libs/LibConstants.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../../utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; import "../../../protocol/Exchange/interfaces/IExchange.sol"; import "../../../tokens/EtherToken/IEtherToken.sol"; import "../../../tokens/ERC20Token/IERC20Token.sol"; diff --git a/contracts/core/contracts/extensions/OrderValidator/OrderValidator.sol b/contracts/core/contracts/extensions/OrderValidator/OrderValidator.sol index 3385d35ef..e3f4f6832 100644 --- a/contracts/core/contracts/extensions/OrderValidator/OrderValidator.sol +++ b/contracts/core/contracts/extensions/OrderValidator/OrderValidator.sol @@ -23,7 +23,7 @@ import "../../protocol/Exchange/interfaces/IExchange.sol"; import "../../protocol/Exchange/libs/LibOrder.sol"; import "../../tokens/ERC20Token/IERC20Token.sol"; import "../../tokens/ERC721Token/IERC721Token.sol"; -import "../../utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; contract OrderValidator { diff --git a/contracts/core/contracts/protocol/AssetProxy/MixinAuthorizable.sol b/contracts/core/contracts/protocol/AssetProxy/MixinAuthorizable.sol index fe9bbf848..08f9b94dc 100644 --- a/contracts/core/contracts/protocol/AssetProxy/MixinAuthorizable.sol +++ b/contracts/core/contracts/protocol/AssetProxy/MixinAuthorizable.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../utils/Ownable/Ownable.sol"; +import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; import "./mixins/MAuthorizable.sol"; diff --git a/contracts/core/contracts/protocol/AssetProxy/interfaces/IAuthorizable.sol b/contracts/core/contracts/protocol/AssetProxy/interfaces/IAuthorizable.sol index ba1d4aa77..96ee05dee 100644 --- a/contracts/core/contracts/protocol/AssetProxy/interfaces/IAuthorizable.sol +++ b/contracts/core/contracts/protocol/AssetProxy/interfaces/IAuthorizable.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../../utils/Ownable/IOwnable.sol"; +import "@0x/contracts-utils/contracts/utils/Ownable/IOwnable.sol"; contract IAuthorizable is diff --git a/contracts/core/contracts/protocol/AssetProxyOwner/AssetProxyOwner.sol b/contracts/core/contracts/protocol/AssetProxyOwner/AssetProxyOwner.sol index 3096340b9..bfc7b5a66 100644 --- a/contracts/core/contracts/protocol/AssetProxyOwner/AssetProxyOwner.sol +++ b/contracts/core/contracts/protocol/AssetProxyOwner/AssetProxyOwner.sol @@ -19,7 +19,7 @@ pragma solidity 0.4.24; import "@0x/contracts-multisig/contracts/multisig/MultiSigWalletWithTimeLock.sol"; -import "../../utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; contract AssetProxyOwner is diff --git a/contracts/core/contracts/protocol/Exchange/MixinAssetProxyDispatcher.sol b/contracts/core/contracts/protocol/Exchange/MixinAssetProxyDispatcher.sol index 87b09b6b3..02aeb4a13 100644 --- a/contracts/core/contracts/protocol/Exchange/MixinAssetProxyDispatcher.sol +++ b/contracts/core/contracts/protocol/Exchange/MixinAssetProxyDispatcher.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../utils/Ownable/Ownable.sol"; +import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; import "./mixins/MAssetProxyDispatcher.sol"; import "../AssetProxy/interfaces/IAssetProxy.sol"; diff --git a/contracts/core/contracts/protocol/Exchange/MixinExchangeCore.sol b/contracts/core/contracts/protocol/Exchange/MixinExchangeCore.sol index 736dcd0b1..da721f78f 100644 --- a/contracts/core/contracts/protocol/Exchange/MixinExchangeCore.sol +++ b/contracts/core/contracts/protocol/Exchange/MixinExchangeCore.sol @@ -19,7 +19,7 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "../../utils/ReentrancyGuard/ReentrancyGuard.sol"; +import "@0x/contracts-utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol"; import "./libs/LibConstants.sol"; import "./libs/LibFillResults.sol"; import "./libs/LibOrder.sol"; diff --git a/contracts/core/contracts/protocol/Exchange/MixinMatchOrders.sol b/contracts/core/contracts/protocol/Exchange/MixinMatchOrders.sol index b4f6bdb26..da1e9d270 100644 --- a/contracts/core/contracts/protocol/Exchange/MixinMatchOrders.sol +++ b/contracts/core/contracts/protocol/Exchange/MixinMatchOrders.sol @@ -14,7 +14,7 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "../../utils/ReentrancyGuard/ReentrancyGuard.sol"; +import "@0x/contracts-utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol"; import "./libs/LibConstants.sol"; import "./libs/LibMath.sol"; import "./libs/LibOrder.sol"; diff --git a/contracts/core/contracts/protocol/Exchange/MixinSignatureValidator.sol b/contracts/core/contracts/protocol/Exchange/MixinSignatureValidator.sol index 033f8e901..711535aa8 100644 --- a/contracts/core/contracts/protocol/Exchange/MixinSignatureValidator.sol +++ b/contracts/core/contracts/protocol/Exchange/MixinSignatureValidator.sol @@ -18,8 +18,8 @@ pragma solidity 0.4.24; -import "../../utils/LibBytes/LibBytes.sol"; -import "../../utils/ReentrancyGuard/ReentrancyGuard.sol"; +import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol"; import "./mixins/MSignatureValidator.sol"; import "./mixins/MTransactions.sol"; import "./interfaces/IWallet.sol"; diff --git a/contracts/core/contracts/protocol/Exchange/MixinWrapperFunctions.sol b/contracts/core/contracts/protocol/Exchange/MixinWrapperFunctions.sol index cddff0e5f..415246358 100644 --- a/contracts/core/contracts/protocol/Exchange/MixinWrapperFunctions.sol +++ b/contracts/core/contracts/protocol/Exchange/MixinWrapperFunctions.sol @@ -19,7 +19,7 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "../../utils/ReentrancyGuard/ReentrancyGuard.sol"; +import "@0x/contracts-utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol"; import "./libs/LibMath.sol"; import "./libs/LibOrder.sol"; import "./libs/LibFillResults.sol"; diff --git a/contracts/core/contracts/protocol/Exchange/libs/LibFillResults.sol b/contracts/core/contracts/protocol/Exchange/libs/LibFillResults.sol index 659ae9a69..fbd9950bf 100644 --- a/contracts/core/contracts/protocol/Exchange/libs/LibFillResults.sol +++ b/contracts/core/contracts/protocol/Exchange/libs/LibFillResults.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../../utils/SafeMath/SafeMath.sol"; +import "@0x/contracts-utils/contracts/utils/SafeMath/SafeMath.sol"; contract LibFillResults is diff --git a/contracts/core/contracts/protocol/Exchange/libs/LibMath.sol b/contracts/core/contracts/protocol/Exchange/libs/LibMath.sol index c0b85ea10..b24876a9c 100644 --- a/contracts/core/contracts/protocol/Exchange/libs/LibMath.sol +++ b/contracts/core/contracts/protocol/Exchange/libs/LibMath.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../../utils/SafeMath/SafeMath.sol"; +import "@0x/contracts-utils/contracts/utils/SafeMath/SafeMath.sol"; contract LibMath is diff --git a/contracts/core/contracts/test/DummyERC20Token/DummyERC20Token.sol b/contracts/core/contracts/test/DummyERC20Token/DummyERC20Token.sol index 412c5d1ad..33028db0c 100644 --- a/contracts/core/contracts/test/DummyERC20Token/DummyERC20Token.sol +++ b/contracts/core/contracts/test/DummyERC20Token/DummyERC20Token.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../utils/Ownable/Ownable.sol"; +import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; import "../../tokens/ERC20Token/MintableERC20Token.sol"; diff --git a/contracts/core/contracts/test/DummyERC721Token/DummyERC721Token.sol b/contracts/core/contracts/test/DummyERC721Token/DummyERC721Token.sol index ac9068d1d..4c978b2df 100644 --- a/contracts/core/contracts/test/DummyERC721Token/DummyERC721Token.sol +++ b/contracts/core/contracts/test/DummyERC721Token/DummyERC721Token.sol @@ -19,7 +19,7 @@ pragma solidity 0.4.24; import "../../tokens/ERC721Token/MintableERC721Token.sol"; -import "../../utils/Ownable/Ownable.sol"; +import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; // solhint-disable no-empty-blocks diff --git a/contracts/core/contracts/test/ReentrantERC20Token/ReentrantERC20Token.sol b/contracts/core/contracts/test/ReentrantERC20Token/ReentrantERC20Token.sol index aa3bf9ab8..3e9091931 100644 --- a/contracts/core/contracts/test/ReentrantERC20Token/ReentrantERC20Token.sol +++ b/contracts/core/contracts/test/ReentrantERC20Token/ReentrantERC20Token.sol @@ -19,7 +19,7 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "../../utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; import "../../tokens/ERC20Token/ERC20Token.sol"; import "../../protocol/Exchange/interfaces/IExchange.sol"; import "../../protocol/Exchange/libs/LibOrder.sol"; diff --git a/contracts/core/contracts/tokens/ERC20Token/MintableERC20Token.sol b/contracts/core/contracts/tokens/ERC20Token/MintableERC20Token.sol index 9dc924422..58bccb5a1 100644 --- a/contracts/core/contracts/tokens/ERC20Token/MintableERC20Token.sol +++ b/contracts/core/contracts/tokens/ERC20Token/MintableERC20Token.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../utils/SafeMath/SafeMath.sol"; +import "@0x/contracts-utils/contracts/utils/SafeMath/SafeMath.sol"; import "./UnlimitedAllowanceERC20Token.sol"; diff --git a/contracts/core/contracts/tokens/ERC721Token/ERC721Token.sol b/contracts/core/contracts/tokens/ERC721Token/ERC721Token.sol index 530f080c0..600cee1ab 100644 --- a/contracts/core/contracts/tokens/ERC721Token/ERC721Token.sol +++ b/contracts/core/contracts/tokens/ERC721Token/ERC721Token.sol @@ -20,7 +20,7 @@ pragma solidity 0.4.24; import "./IERC721Token.sol"; import "./IERC721Receiver.sol"; -import "../../utils/SafeMath/SafeMath.sol"; +import "@0x/contracts-utils/contracts/utils/SafeMath/SafeMath.sol"; contract ERC721Token is diff --git a/contracts/core/package.json b/contracts/core/package.json index b50fc7a17..701e1866e 100644 --- a/contracts/core/package.json +++ b/contracts/core/package.json @@ -75,6 +75,7 @@ "@0x/base-contract": "^3.0.8", "@0x/order-utils": "^3.0.4", "@0x/contracts-multisig": "^1.0.0", + "@0x/contracts-utils": "^1.0.0", "@0x/types": "^1.3.0", "@0x/typescript-typings": "^3.0.4", "@0x/utils": "^2.0.6", diff --git a/contracts/core/src/artifacts/index.ts b/contracts/core/src/artifacts/index.ts index f217adb8e..b925ec87f 100644 --- a/contracts/core/src/artifacts/index.ts +++ b/contracts/core/src/artifacts/index.ts @@ -25,9 +25,7 @@ import * as OrderValidator from '../../generated-artifacts/OrderValidator.json'; import * as ReentrantERC20Token from '../../generated-artifacts/ReentrantERC20Token.json'; import * as TestAssetProxyDispatcher from '../../generated-artifacts/TestAssetProxyDispatcher.json'; import * as TestAssetProxyOwner from '../../generated-artifacts/TestAssetProxyOwner.json'; -import * as TestConstants from '../../generated-artifacts/TestConstants.json'; import * as TestExchangeInternals from '../../generated-artifacts/TestExchangeInternals.json'; -import * as TestLibBytes from '../../generated-artifacts/TestLibBytes.json'; import * as TestLibs from '../../generated-artifacts/TestLibs.json'; import * as TestSignatureValidator from '../../generated-artifacts/TestSignatureValidator.json'; import * as TestStaticCallReceiver from '../../generated-artifacts/TestStaticCallReceiver.json'; @@ -63,9 +61,7 @@ export const artifacts = { ReentrantERC20Token: ReentrantERC20Token as ContractArtifact, TestAssetProxyDispatcher: TestAssetProxyDispatcher as ContractArtifact, TestAssetProxyOwner: TestAssetProxyOwner as ContractArtifact, - TestConstants: TestConstants as ContractArtifact, TestExchangeInternals: TestExchangeInternals as ContractArtifact, - TestLibBytes: TestLibBytes as ContractArtifact, TestLibs: TestLibs as ContractArtifact, TestSignatureValidator: TestSignatureValidator as ContractArtifact, TestStaticCallReceiver: TestStaticCallReceiver as ContractArtifact, diff --git a/contracts/core/src/wrappers/index.ts b/contracts/core/src/wrappers/index.ts index 06a139209..0a64a4db0 100644 --- a/contracts/core/src/wrappers/index.ts +++ b/contracts/core/src/wrappers/index.ts @@ -20,9 +20,7 @@ export * from '../../generated-wrappers/order_validator'; export * from '../../generated-wrappers/reentrant_erc20_token'; export * from '../../generated-wrappers/test_asset_proxy_dispatcher'; export * from '../../generated-wrappers/test_asset_proxy_owner'; -export * from '../../generated-wrappers/test_constants'; export * from '../../generated-wrappers/test_exchange_internals'; -export * from '../../generated-wrappers/test_lib_bytes'; export * from '../../generated-wrappers/test_libs'; export * from '../../generated-wrappers/test_signature_validator'; export * from '../../generated-wrappers/test_static_call_receiver'; diff --git a/contracts/core/test/exchange/libs.ts b/contracts/core/test/exchange/libs.ts index f52992c13..44ff6a844 100644 --- a/contracts/core/test/exchange/libs.ts +++ b/contracts/core/test/exchange/libs.ts @@ -13,7 +13,6 @@ import { SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; -import { TestConstantsContract } from '../../generated-wrappers/test_constants'; import { TestLibsContract } from '../../generated-wrappers/test_libs'; import { artifacts } from '../../src/artifacts'; @@ -26,7 +25,6 @@ describe('Exchange libs', () => { let signedOrder: SignedOrder; let orderFactory: OrderFactory; let libs: TestLibsContract; - let testConstants: TestConstantsContract; before(async () => { await blockchainLifecycle.startAsync(); @@ -38,11 +36,6 @@ describe('Exchange libs', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const makerAddress = accounts[0]; libs = await TestLibsContract.deployFrom0xArtifactAsync(artifacts.TestLibs, provider, txDefaults); - testConstants = await TestConstantsContract.deployFrom0xArtifactAsync( - artifacts.TestConstants, - provider, - txDefaults, - ); const defaultOrderParams = { ...constants.STATIC_ORDER_PARAMS, @@ -62,15 +55,6 @@ describe('Exchange libs', () => { afterEach(async () => { await blockchainLifecycle.revertAsync(); }); - - describe('LibConstants', () => { - describe('ZRX_ASSET_DATA', () => { - it('should have the correct ZRX_ASSET_DATA', async () => { - const isValid = await testConstants.assertValidZrxAssetData.callAsync(); - expect(isValid).to.be.equal(true); - }); - }); - }); // Note(albrow): These tests are designed to be supplemental to the // combinatorial tests in test/exchange/internal. They test specific edge // cases that are not covered by the combinatorial tests. diff --git a/contracts/core/tsconfig.json b/contracts/core/tsconfig.json index 57ab35732..82d37b51e 100644 --- a/contracts/core/tsconfig.json +++ b/contracts/core/tsconfig.json @@ -32,9 +32,7 @@ "./generated-artifacts/ReentrantERC20Token.json", "./generated-artifacts/TestAssetProxyDispatcher.json", "./generated-artifacts/TestAssetProxyOwner.json", - "./generated-artifacts/TestConstants.json", "./generated-artifacts/TestExchangeInternals.json", - "./generated-artifacts/TestLibBytes.json", "./generated-artifacts/TestLibs.json", "./generated-artifacts/TestSignatureValidator.json", "./generated-artifacts/TestStaticCallReceiver.json", diff --git a/contracts/utils/.solhint.json b/contracts/utils/.solhint.json new file mode 100644 index 000000000..076afe9f3 --- /dev/null +++ b/contracts/utils/.solhint.json @@ -0,0 +1,20 @@ +{ + "extends": "default", + "rules": { + "avoid-low-level-calls": false, + "avoid-tx-origin": "warn", + "bracket-align": false, + "code-complexity": false, + "const-name-snakecase": "error", + "expression-indent": "error", + "function-max-lines": false, + "func-order": "error", + "indent": ["error", 4], + "max-line-length": ["warn", 160], + "no-inline-assembly": false, + "quotes": ["error", "double"], + "separate-by-one-line-in-contract": "error", + "space-after-comma": "error", + "statement-indent": "error" + } +} diff --git a/contracts/utils/README.md b/contracts/utils/README.md new file mode 100644 index 000000000..e7c7b49ff --- /dev/null +++ b/contracts/utils/README.md @@ -0,0 +1,70 @@ +## Contracts utils + +Smart contracts utils used in the 0x protocol. + +## Usage + +Contracts can be found in the [contracts](./contracts) directory. The contents of this directory are broken down into the following subdirectories: + +* [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. + +## 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)](https://github.com/0xProject/ZEIPs) repository and follow the contribution guidelines provided therein. + +Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. + +### Install Dependencies + +If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: + +```bash +yarn config set workspaces-experimental true +``` + +Then install dependencies + +```bash +yarn install +``` + +### Build + +To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: + +```bash +PKG=@0x/contracts-utils yarn build +``` + +Or continuously rebuild on change: + +```bash +PKG=@0x/contracts-utils yarn watch +``` + +### Clean + +```bash +yarn clean +``` + +### Lint + +```bash +yarn lint +``` + +### Run Tests + +```bash +yarn test +``` + +#### Testing options + +Contracts testing options like coverage, profiling, revert traces or backing node choosing - are described [here](../TESTING.md). diff --git a/contracts/utils/compiler.json b/contracts/utils/compiler.json new file mode 100644 index 000000000..1524c1eaa --- /dev/null +++ b/contracts/utils/compiler.json @@ -0,0 +1,22 @@ +{ + "artifactsDir": "./generated-artifacts", + "contractsDir": "./contracts", + "compilerSettings": { + "optimizer": { + "enabled": true, + "runs": 1000000 + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "evm.bytecode.object", + "evm.bytecode.sourceMap", + "evm.deployedBytecode.object", + "evm.deployedBytecode.sourceMap" + ] + } + } + }, + "contracts": ["TestConstants", "TestLibBytes", "LibBytes", "Ownable", "IOwnable", "ReentrancyGuard", "SafeMath"] +} diff --git a/contracts/core/contracts/test/TestConstants/TestConstants.sol b/contracts/utils/contracts/test/TestConstants/TestConstants.sol index 1275d007b..3c852173b 100644 --- a/contracts/core/contracts/test/TestConstants/TestConstants.sol +++ b/contracts/utils/contracts/test/TestConstants/TestConstants.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; // solhint-disable max-line-length diff --git a/contracts/core/contracts/test/TestLibBytes/TestLibBytes.sol b/contracts/utils/contracts/test/TestLibBytes/TestLibBytes.sol index 00d861e61..444a3e717 100644 --- a/contracts/core/contracts/test/TestLibBytes/TestLibBytes.sol +++ b/contracts/utils/contracts/test/TestLibBytes/TestLibBytes.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; contract TestLibBytes { diff --git a/contracts/core/contracts/utils/LibBytes/LibBytes.sol b/contracts/utils/contracts/utils/LibBytes/LibBytes.sol index 369f588ad..369f588ad 100644 --- a/contracts/core/contracts/utils/LibBytes/LibBytes.sol +++ b/contracts/utils/contracts/utils/LibBytes/LibBytes.sol diff --git a/contracts/core/contracts/utils/Ownable/IOwnable.sol b/contracts/utils/contracts/utils/Ownable/IOwnable.sol index 5deb13497..5deb13497 100644 --- a/contracts/core/contracts/utils/Ownable/IOwnable.sol +++ b/contracts/utils/contracts/utils/Ownable/IOwnable.sol diff --git a/contracts/core/contracts/utils/Ownable/Ownable.sol b/contracts/utils/contracts/utils/Ownable/Ownable.sol index 0c830be68..0c830be68 100644 --- a/contracts/core/contracts/utils/Ownable/Ownable.sol +++ b/contracts/utils/contracts/utils/Ownable/Ownable.sol diff --git a/contracts/core/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol b/contracts/utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol index 9f98a7a16..9f98a7a16 100644 --- a/contracts/core/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol +++ b/contracts/utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol diff --git a/contracts/core/contracts/utils/SafeMath/SafeMath.sol b/contracts/utils/contracts/utils/SafeMath/SafeMath.sol index 2855edb9d..2855edb9d 100644 --- a/contracts/core/contracts/utils/SafeMath/SafeMath.sol +++ b/contracts/utils/contracts/utils/SafeMath/SafeMath.sol diff --git a/contracts/utils/package.json b/contracts/utils/package.json new file mode 100644 index 000000000..94b3cb7c7 --- /dev/null +++ b/contracts/utils/package.json @@ -0,0 +1,89 @@ +{ + "private": true, + "name": "@0x/contracts-utils", + "version": "1.0.0", + "engines": { + "node": ">=6.12" + }, + "description": "Smart contract utils of 0x protocol", + "main": "lib/src/index.js", + "directories": { + "test": "test" + }, + "scripts": { + "build": "yarn pre_build && tsc -b", + "build:ci": "yarn build", + "pre_build": "run-s compile generate_contract_wrappers", + "test": "yarn run_mocha", + "rebuild_and_test": "run-s build test", + "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", + "test:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html", + "test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha", + "run_mocha": + "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit", + "compile": "sol-compiler --contracts-dir contracts", + "clean": "shx rm -rf lib generated-artifacts generated-wrappers", + "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ../../node_modules/@0x/abi-gen-templates/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/partials/**/*.handlebars' --output generated-wrappers --backend ethers", + "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", + "coverage:report:text": "istanbul report text", + "coverage:report:html": "istanbul report html && open coverage/index.html", + "profiler:report:html": "istanbul report html && open coverage/index.html", + "coverage:report:lcov": "istanbul report lcov", + "test:circleci": "yarn test", + "lint-contracts": "solhint contracts/**/**/**/**/*.sol" + }, + "config": { + "abis": "generated-artifacts/@(IOwnable|Ownable|LibBytes|ReentrancyGuard|SafeMath|TestConstants|TestLibBytes).json" + }, + "repository": { + "type": "git", + "url": "https://github.com/0xProject/0x-monorepo.git" + }, + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/0xProject/0x-monorepo/issues" + }, + "homepage": "https://github.com/0xProject/0x-monorepo/contracts/core/README.md", + "devDependencies": { + "@0x/contracts-test-utils": "^1.0.0", + "@0x/abi-gen": "^1.0.17", + "@0x/dev-utils": "^1.0.19", + "@0x/sol-compiler": "^1.1.14", + "@0x/sol-cov": "^2.1.14", + "@0x/subproviders": "^2.1.6", + "@0x/tslint-config": "^1.0.10", + "@types/bn.js": "^4.11.0", + "@types/lodash": "4.14.104", + "@types/node": "*", + "@types/yargs": "^10.0.0", + "chai": "^4.0.1", + "chai-as-promised": "^7.1.0", + "chai-bignumber": "^2.0.1", + "dirty-chai": "^2.0.1", + "make-promises-safe": "^1.1.0", + "ethereumjs-abi": "0.6.5", + "mocha": "^4.1.0", + "npm-run-all": "^4.1.2", + "shx": "^0.2.2", + "solc": "^0.4.24", + "solhint": "^1.2.1", + "tslint": "5.11.0", + "typescript": "3.0.1", + "yargs": "^10.0.3" + }, + "dependencies": { + "@0x/base-contract": "^3.0.8", + "@0x/order-utils": "^3.0.4", + "@0x/contracts-multisig": "^1.0.0", + "@0x/types": "^1.3.0", + "@0x/typescript-typings": "^3.0.4", + "@0x/utils": "^2.0.6", + "@0x/web3-wrapper": "^3.1.6", + "ethereum-types": "^1.1.2", + "ethereumjs-util": "^5.1.1", + "lodash": "^4.17.5" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/contracts/utils/src/artifacts/index.ts b/contracts/utils/src/artifacts/index.ts new file mode 100644 index 000000000..a5c2b215c --- /dev/null +++ b/contracts/utils/src/artifacts/index.ts @@ -0,0 +1,19 @@ +import { ContractArtifact } from 'ethereum-types'; + +import * as IOwnable from '../../generated-artifacts/IOwnable.json'; +import * as LibBytes from '../../generated-artifacts/LibBytes.json'; +import * as Ownable from '../../generated-artifacts/Ownable.json'; +import * as ReentrancyGuard from '../../generated-artifacts/ReentrancyGuard.json'; +import * as SafeMath from '../../generated-artifacts/SafeMath.json'; +import * as TestConstants from '../../generated-artifacts/TestConstants.json'; +import * as TestLibBytes from '../../generated-artifacts/TestLibBytes.json'; + +export const artifacts = { + TestConstants: TestConstants as ContractArtifact, + TestLibBytes: TestLibBytes as ContractArtifact, + IOwnable: IOwnable as ContractArtifact, + LibBytes: LibBytes as ContractArtifact, + Ownable: Ownable as ContractArtifact, + SafeMath: SafeMath as ContractArtifact, + ReentrancyGuard: ReentrancyGuard as ContractArtifact, +}; diff --git a/contracts/utils/src/index.ts b/contracts/utils/src/index.ts new file mode 100644 index 000000000..d55f08ea2 --- /dev/null +++ b/contracts/utils/src/index.ts @@ -0,0 +1,2 @@ +export * from './artifacts'; +export * from './wrappers'; diff --git a/contracts/utils/src/wrappers/index.ts b/contracts/utils/src/wrappers/index.ts new file mode 100644 index 000000000..823b7fa4b --- /dev/null +++ b/contracts/utils/src/wrappers/index.ts @@ -0,0 +1,2 @@ +export * from '../../generated-wrappers/test_constants'; +export * from '../../generated-wrappers/test_lib_bytes'; diff --git a/contracts/utils/test/global_hooks.ts b/contracts/utils/test/global_hooks.ts new file mode 100644 index 000000000..f8ace376a --- /dev/null +++ b/contracts/utils/test/global_hooks.ts @@ -0,0 +1,17 @@ +import { env, EnvVars } from '@0x/dev-utils'; + +import { coverage, profiler, provider } from '@0x/contracts-test-utils'; +before('start web3 provider', () => { + provider.start(); +}); +after('generate coverage report', async () => { + if (env.parseBoolean(EnvVars.SolidityCoverage)) { + const coverageSubprovider = coverage.getCoverageSubproviderSingleton(); + await coverageSubprovider.writeCoverageAsync(); + } + if (env.parseBoolean(EnvVars.SolidityProfiler)) { + const profilerSubprovider = profiler.getProfilerSubproviderSingleton(); + await profilerSubprovider.writeProfilerOutputAsync(); + } + provider.stop(); +}); diff --git a/contracts/core/test/libraries/lib_bytes.ts b/contracts/utils/test/lib_bytes.ts index 9338e6e7f..985a98943 100644 --- a/contracts/core/test/libraries/lib_bytes.ts +++ b/contracts/utils/test/lib_bytes.ts @@ -16,8 +16,8 @@ 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/artifacts'; +import { TestLibBytesContract } from '../generated-wrappers/test_lib_bytes'; +import { artifacts } from '../src'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/utils/test/libs.ts b/contracts/utils/test/libs.ts new file mode 100644 index 000000000..81596b2e4 --- /dev/null +++ b/contracts/utils/test/libs.ts @@ -0,0 +1,34 @@ +import { chaiSetup, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils'; +import { BlockchainLifecycle } from '@0x/dev-utils'; +import * as chai from 'chai'; + +import { TestConstantsContract } from '../generated-wrappers/test_constants'; +import { artifacts } from '../src'; + +chaiSetup.configure(); +const expect = chai.expect; + +const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); + +describe('Libs', () => { + beforeEach(async () => { + await blockchainLifecycle.startAsync(); + }); + afterEach(async () => { + await blockchainLifecycle.revertAsync(); + }); + + describe('LibConstants', () => { + describe('ZRX_ASSET_DATA', () => { + it('should have the correct ZRX_ASSET_DATA', async () => { + const testConstants = await TestConstantsContract.deployFrom0xArtifactAsync( + artifacts.TestConstants, + provider, + txDefaults, + ); + const isValid = await testConstants.assertValidZrxAssetData.callAsync(); + expect(isValid).to.be.equal(true); + }); + }); + }); +}); diff --git a/contracts/utils/tsconfig.json b/contracts/utils/tsconfig.json new file mode 100644 index 000000000..68251e6b0 --- /dev/null +++ b/contracts/utils/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { + "outDir": "lib", + "rootDir": ".", + "resolveJsonModule": true + }, + "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], + "files": [ + "./generated-artifacts/TestConstants.json", + "./generated-artifacts/TestLibBytes.json", + "./generated-artifacts/IOwnable.json", + "./generated-artifacts/Ownable.json", + "./generated-artifacts/LibBytes.json", + "./generated-artifacts/SafeMath.json", + "./generated-artifacts/ReentrancyGuard.json" + ], + "exclude": ["./deploy/solc/solc_bin"] +} diff --git a/contracts/utils/tslint.json b/contracts/utils/tslint.json new file mode 100644 index 000000000..1bb3ac2a2 --- /dev/null +++ b/contracts/utils/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": ["@0x/tslint-config"], + "rules": { + "custom-no-magic-numbers": false + } +} |