aboutsummaryrefslogtreecommitdiffstats
path: root/packages/base-contract
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base-contract')
-rw-r--r--packages/base-contract/.npmignore6
-rw-r--r--packages/base-contract/CHANGELOG.json370
-rw-r--r--packages/base-contract/CHANGELOG.md161
-rw-r--r--packages/base-contract/README.md63
-rw-r--r--packages/base-contract/coverage/.gitkeep0
-rw-r--r--packages/base-contract/package.json53
-rw-r--r--packages/base-contract/src/globals.d.ts6
-rw-r--r--packages/base-contract/src/index.ts174
-rw-r--r--packages/base-contract/src/utils.ts25
-rw-r--r--packages/base-contract/test/base_contract_test.ts114
-rw-r--r--packages/base-contract/test/utils_test.ts108
-rw-r--r--packages/base-contract/tsconfig.json8
-rw-r--r--packages/base-contract/tslint.json3
13 files changed, 0 insertions, 1091 deletions
diff --git a/packages/base-contract/.npmignore b/packages/base-contract/.npmignore
deleted file mode 100644
index 24e65ad5b..000000000
--- a/packages/base-contract/.npmignore
+++ /dev/null
@@ -1,6 +0,0 @@
-.*
-yarn-error.log
-/scripts/
-/src/
-tsconfig.json
-/lib/monorepo_scripts/
diff --git a/packages/base-contract/CHANGELOG.json b/packages/base-contract/CHANGELOG.json
deleted file mode 100644
index 63b1fe8f7..000000000
--- a/packages/base-contract/CHANGELOG.json
+++ /dev/null
@@ -1,370 +0,0 @@
-[
- {
- "version": "4.0.0",
- "changes": [
- {
- "note": "Upgrade the bignumber.js to v8.0.2",
- "pr": 1517
- }
- ]
- },
- {
- "timestamp": 1547561734,
- "version": "3.0.13",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1547225310,
- "version": "3.0.12",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1547040760,
- "version": "3.0.11",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "version": "3.0.10",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ],
- "timestamp": 1544739608
- },
- {
- "version": "3.0.9",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ],
- "timestamp": 1544570656
- },
- {
- "timestamp": 1543401373,
- "version": "3.0.8",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1542821676,
- "version": "3.0.7",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1542208198,
- "version": "3.0.6",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1542134075,
- "version": "3.0.5",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1542028948,
- "version": "3.0.4",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "version": "3.0.3",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ],
- "timestamp": 1541740904
- },
- {
- "timestamp": 1539871071,
- "version": "3.0.2",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "version": "3.0.1",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ],
- "timestamp": 1538693146
- },
- {
- "version": "3.0.0",
- "changes": [
- {
- "note": "Change the way we detect BN to work with the newest ethers.js",
- "pr": 1069
- },
- {
- "note": "Add baseContract._throwIfRevertWithReasonCallResult",
- "pr": 1069
- }
- ],
- "timestamp": 1538157789
- },
- {
- "timestamp": 1537907159,
- "version": "2.0.5",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1537875740,
- "version": "2.0.4",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1537541580,
- "version": "2.0.3",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1536142250,
- "version": "2.0.2",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1535377027,
- "version": "2.0.1",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1535133899,
- "version": "2.0.0",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "version": "2.0.0-rc.1",
- "changes": [
- {
- "pr": 915,
- "note": "Added strict encoding/decoding checks for sendTransaction and call"
- }
- ],
- "timestamp": 1534210131
- },
- {
- "timestamp": 1532619515,
- "version": "1.0.4",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1532614997,
- "version": "1.0.3",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1532605697,
- "version": "1.0.2",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1532357734,
- "version": "1.0.1",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1532043000,
- "version": "1.0.0",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1531919263,
- "version": "0.3.6",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1531149657,
- "version": "0.3.5",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "version": "0.3.4",
- "changes": [
- {
- "note": "Update EthersJs to fix the `value.toLowerCase()` is not a function bug caused by `ethers.js` breaking patch version https://github.com/ethers-io/ethers.js/issues/201"
- }
- ],
- "timestamp": 1529397769
- },
- {
- "timestamp": 1527810075,
- "version": "0.3.3",
- "changes": [
- {
- "note": "Incorrect publish that was unpublished"
- }
- ]
- },
- {
- "timestamp": 1527008270,
- "version": "0.3.2",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "timestamp": 1525477860,
- "version": "0.3.1",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "version": "0.3.0",
- "changes": [
- {
- "note": "Update ethers-contracts to ethers.js",
- "pr": 540
- }
- ],
- "timestamp": 1525428773
- },
- {
- "timestamp": 1524044013,
- "version": "0.2.1",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "version": "0.2.0",
- "changes": [
- {
- "note": "Contract wrappers now accept Provider and defaults instead of Web3Wrapper",
- "pr": 501
- }
- ],
- "timestamp": 1523462196
- },
- {
- "version": "0.1.0",
- "changes": [
- {
- "note": "Add tests for traversing ABI tree",
- "pr": 485
- },
- {
- "note": "Fix ABI tuples traversing",
- "pr": 485
- },
- {
- "note": "Fix ABI arrays traversing",
- "pr": 485
- }
- ],
- "timestamp": 1522673609
- },
- {
- "timestamp": 1522658513,
- "version": "0.0.6",
- "changes": [
- {
- "note": "Dependencies updated"
- }
- ]
- },
- {
- "version": "0.0.2",
- "changes": [
- {
- "note": "Initial release"
- }
- ],
- "timestamp": 1520089200
- }
-]
diff --git a/packages/base-contract/CHANGELOG.md b/packages/base-contract/CHANGELOG.md
deleted file mode 100644
index 975a56fd4..000000000
--- a/packages/base-contract/CHANGELOG.md
+++ /dev/null
@@ -1,161 +0,0 @@
-<!--
-changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly.
-Edit the package's CHANGELOG.json file only.
--->
-
-CHANGELOG
-
-## v3.0.13 - _January 15, 2019_
-
- * Dependencies updated
-
-## v3.0.12 - _January 11, 2019_
-
- * Dependencies updated
-
-## v3.0.11 - _January 9, 2019_
-
- * Dependencies updated
-
-## v3.0.10 - _December 13, 2018_
-
- * Dependencies updated
-
-## v3.0.9 - _December 11, 2018_
-
- * Dependencies updated
-
-## v3.0.8 - _November 28, 2018_
-
- * Dependencies updated
-
-## v3.0.7 - _November 21, 2018_
-
- * Dependencies updated
-
-## v3.0.6 - _November 14, 2018_
-
- * Dependencies updated
-
-## v3.0.5 - _November 13, 2018_
-
- * Dependencies updated
-
-## v3.0.4 - _November 12, 2018_
-
- * Dependencies updated
-
-## v3.0.3 - _November 9, 2018_
-
- * Dependencies updated
-
-## v3.0.2 - _October 18, 2018_
-
- * Dependencies updated
-
-## v3.0.1 - _October 4, 2018_
-
- * Dependencies updated
-
-## v3.0.0 - _September 28, 2018_
-
- * Change the way we detect BN to work with the newest ethers.js (#1069)
- * Add baseContract._throwIfRevertWithReasonCallResult (#1069)
-
-## v2.0.5 - _September 25, 2018_
-
- * Dependencies updated
-
-## v2.0.4 - _September 25, 2018_
-
- * Dependencies updated
-
-## v2.0.3 - _September 21, 2018_
-
- * Dependencies updated
-
-## v2.0.2 - _September 5, 2018_
-
- * Dependencies updated
-
-## v2.0.1 - _August 27, 2018_
-
- * Dependencies updated
-
-## v2.0.0 - _August 24, 2018_
-
- * Dependencies updated
-
-## v2.0.0-rc.1 - _August 14, 2018_
-
- * Added strict encoding/decoding checks for sendTransaction and call (#915)
-
-## v1.0.4 - _July 26, 2018_
-
- * Dependencies updated
-
-## v1.0.3 - _July 26, 2018_
-
- * Dependencies updated
-
-## v1.0.2 - _July 26, 2018_
-
- * Dependencies updated
-
-## v1.0.1 - _July 23, 2018_
-
- * Dependencies updated
-
-## v1.0.0 - _July 19, 2018_
-
- * Dependencies updated
-
-## v0.3.6 - _July 18, 2018_
-
- * Dependencies updated
-
-## v0.3.5 - _July 9, 2018_
-
- * Dependencies updated
-
-## v0.3.4 - _June 19, 2018_
-
- * Update EthersJs to fix the `value.toLowerCase()` is not a function bug caused by `ethers.js` breaking patch version https://github.com/ethers-io/ethers.js/issues/201
-
-## v0.3.3 - _May 31, 2018_
-
- * Incorrect publish that was unpublished
-
-## v0.3.2 - _May 22, 2018_
-
- * Dependencies updated
-
-## v0.3.1 - _May 4, 2018_
-
- * Dependencies updated
-
-## v0.3.0 - _May 4, 2018_
-
- * Update ethers-contracts to ethers.js (#540)
-
-## v0.2.1 - _April 18, 2018_
-
- * Dependencies updated
-
-## v0.2.0 - _April 11, 2018_
-
- * Contract wrappers now accept Provider and defaults instead of Web3Wrapper (#501)
-
-## v0.1.0 - _April 2, 2018_
-
- * Add tests for traversing ABI tree (#485)
- * Fix ABI tuples traversing (#485)
- * Fix ABI arrays traversing (#485)
-
-## v0.0.6 - _April 2, 2018_
-
- * Dependencies updated
-
-## v0.0.2 - _March 3, 2018_
-
- * Initial release
diff --git a/packages/base-contract/README.md b/packages/base-contract/README.md
deleted file mode 100644
index b6ea05b74..000000000
--- a/packages/base-contract/README.md
+++ /dev/null
@@ -1,63 +0,0 @@
-## @0x/base-contract
-
-BaseContract to derive all auto-generated wrappers from
-
-## Installation
-
-```bash
-yarn add @0x/base-contract
-```
-
-If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`:
-
-```json
-"compilerOptions": {
- "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"],
-}
-```
-
-## Usage
-
-```javascript
-import { BaseContract } from '@0x/base-contract';
-```
-
-## 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.
-
-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/base-contract yarn build
-```
-
-Or continuously rebuild on change:
-
-```bash
-PKG=@0x/base-contract yarn watch
-```
-
-### Lint
-
-```bash
-yarn lint
-```
diff --git a/packages/base-contract/coverage/.gitkeep b/packages/base-contract/coverage/.gitkeep
deleted file mode 100644
index e69de29bb..000000000
--- a/packages/base-contract/coverage/.gitkeep
+++ /dev/null
diff --git a/packages/base-contract/package.json b/packages/base-contract/package.json
deleted file mode 100644
index db09b16a1..000000000
--- a/packages/base-contract/package.json
+++ /dev/null
@@ -1,53 +0,0 @@
-{
- "name": "@0x/base-contract",
- "version": "3.0.13",
- "engines": {
- "node": ">=6.12"
- },
- "description": "0x Base TS contract",
- "main": "lib/src/index.js",
- "types": "lib/src/index.d.ts",
- "scripts": {
- "build": "tsc -b",
- "build:ci": "yarn build",
- "clean": "shx rm -rf lib",
- "test": "yarn run_mocha",
- "rebuild_and_test": "run-s clean build test",
- "test:circleci": "yarn test:coverage",
- "run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --bail --exit",
- "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
- "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
- "lint": "tslint --format stylish --project ."
- },
- "license": "Apache-2.0",
- "repository": {
- "type": "git",
- "url": "https://github.com/0xProject/0x-monorepo.git"
- },
- "bugs": {
- "url": "https://github.com/0xProject/0x-monorepo/issues"
- },
- "homepage": "https://github.com/0xProject/0x-monorepo/packages/base-contract/README.md",
- "devDependencies": {
- "@0x/tslint-config": "^2.0.2",
- "@types/lodash": "4.14.104",
- "chai": "^4.0.1",
- "make-promises-safe": "^1.1.0",
- "mocha": "^4.1.0",
- "npm-run-all": "^4.1.2",
- "shx": "^0.2.2",
- "tslint": "5.11.0",
- "typescript": "3.0.1"
- },
- "dependencies": {
- "@0x/typescript-typings": "^3.0.8",
- "@0x/utils": "^3.0.1",
- "@0x/web3-wrapper": "^3.2.4",
- "ethereum-types": "^1.1.6",
- "ethers": "~4.0.4",
- "lodash": "^4.17.5"
- },
- "publishConfig": {
- "access": "public"
- }
-}
diff --git a/packages/base-contract/src/globals.d.ts b/packages/base-contract/src/globals.d.ts
deleted file mode 100644
index 94e63a32d..000000000
--- a/packages/base-contract/src/globals.d.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-declare module '*.json' {
- const json: any;
- /* tslint:disable */
- export default json;
- /* tslint:enable */
-}
diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts
deleted file mode 100644
index 0238106f3..000000000
--- a/packages/base-contract/src/index.ts
+++ /dev/null
@@ -1,174 +0,0 @@
-import { AbiEncoder, abiUtils, BigNumber } from '@0x/utils';
-import { Web3Wrapper } from '@0x/web3-wrapper';
-import {
- AbiDefinition,
- AbiType,
- ConstructorAbi,
- ContractAbi,
- DataItem,
- MethodAbi,
- Provider,
- TxData,
- TxDataPayable,
-} from 'ethereum-types';
-import * as ethers from 'ethers';
-import * as _ from 'lodash';
-
-import { formatABIDataItem } from './utils';
-
-export interface AbiEncoderByFunctionSignature {
- [key: string]: AbiEncoder.Method;
-}
-
-const REVERT_ERROR_SELECTOR = '08c379a0';
-const REVERT_ERROR_SELECTOR_OFFSET = 2;
-const REVERT_ERROR_SELECTOR_BYTES_LENGTH = 4;
-const REVERT_ERROR_SELECTOR_END = REVERT_ERROR_SELECTOR_OFFSET + REVERT_ERROR_SELECTOR_BYTES_LENGTH * 2;
-
-export class BaseContract {
- protected _abiEncoderByFunctionSignature: AbiEncoderByFunctionSignature;
- protected _web3Wrapper: Web3Wrapper;
- public abi: ContractAbi;
- public address: string;
- public contractName: string;
- public constructorArgs: any[] = [];
- protected static _formatABIDataItemList(
- abis: DataItem[],
- values: any[],
- formatter: (type: string, value: any) => any,
- ): any {
- return _.map(values, (value: any, i: number) => formatABIDataItem(abis[i], value, formatter));
- }
- protected static _lowercaseAddress(type: string, value: string): string {
- return type === 'address' ? value.toLowerCase() : value;
- }
- protected static _bigNumberToString(_type: string, value: any): any {
- return BigNumber.isBigNumber(value) ? value.toString() : value;
- }
- protected static _lookupConstructorAbi(abi: ContractAbi): ConstructorAbi {
- const constructorAbiIfExists = _.find(
- abi,
- (abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Constructor,
- // tslint:disable-next-line:no-unnecessary-type-assertion
- ) as ConstructorAbi | undefined;
- if (!_.isUndefined(constructorAbiIfExists)) {
- return constructorAbiIfExists;
- } else {
- // If the constructor is not explicitly defined, it won't be included in the ABI. It is
- // still callable however, so we construct what the ABI would look like were it to exist.
- const defaultConstructorAbi: ConstructorAbi = {
- type: AbiType.Constructor,
- stateMutability: 'nonpayable',
- payable: false,
- inputs: [],
- };
- return defaultConstructorAbi;
- }
- }
- protected static async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>(
- txData: T,
- txDefaults: Partial<TxData>,
- estimateGasAsync?: (txData: T) => Promise<number>,
- ): Promise<TxData> {
- // Gas amount sourced with the following priorities:
- // 1. Optional param passed in to public method call
- // 2. Global config passed in at library instantiation
- // 3. Gas estimate calculation + safety margin
- const removeUndefinedProperties = _.pickBy.bind(_);
- const txDataWithDefaults = {
- ...removeUndefinedProperties(txDefaults),
- ...removeUndefinedProperties(txData),
- };
- if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) {
- txDataWithDefaults.gas = await estimateGasAsync(txDataWithDefaults);
- }
- return txDataWithDefaults;
- }
- protected static _throwIfRevertWithReasonCallResult(rawCallResult: string): void {
- if (rawCallResult.slice(REVERT_ERROR_SELECTOR_OFFSET, REVERT_ERROR_SELECTOR_END) === REVERT_ERROR_SELECTOR) {
- const revertReasonArray = AbiEncoder.create('(string)').decodeAsArray(
- ethers.utils.hexDataSlice(rawCallResult, REVERT_ERROR_SELECTOR_BYTES_LENGTH),
- );
- if (revertReasonArray.length !== 1) {
- throw new Error(
- `Cannot safely decode revert reason: Expected an array with one element, got ${revertReasonArray}`,
- );
- }
- const revertReason = revertReasonArray[0];
- throw new Error(revertReason);
- }
- }
- // Throws if the given arguments cannot be safely/correctly encoded based on
- // the given inputAbi. An argument may not be considered safely encodeable
- // if it overflows the corresponding Solidity type, there is a bug in the
- // encoder, or the encoder performs unsafe type coercion.
- public static strictArgumentEncodingCheck(inputAbi: DataItem[], args: any[]): string {
- const abiEncoder = AbiEncoder.create(inputAbi);
- const params = abiUtils.parseEthersParams(inputAbi);
- const rawEncoded = abiEncoder.encode(args);
- const rawDecoded = abiEncoder.decodeAsArray(rawEncoded);
- for (let i = 0; i < rawDecoded.length; i++) {
- const original = args[i];
- const decoded = rawDecoded[i];
- if (!abiUtils.isAbiDataEqual(params.names[i], params.types[i], original, decoded)) {
- throw new Error(
- `Cannot safely encode argument: ${params.names[i]} (${original}) of type ${
- params.types[i]
- }. (Possible type overflow or other encoding error)`,
- );
- }
- }
- return rawEncoded;
- }
- protected _lookupAbiEncoder(functionSignature: string): AbiEncoder.Method {
- const abiEncoder = this._abiEncoderByFunctionSignature[functionSignature];
- if (_.isUndefined(abiEncoder)) {
- throw new Error(`Failed to lookup method with function signature '${functionSignature}'`);
- }
- return abiEncoder;
- }
- protected _lookupAbi(functionSignature: string): MethodAbi {
- const methodAbi = _.find(this.abi, (abiDefinition: AbiDefinition) => {
- if (abiDefinition.type !== AbiType.Function) {
- return false;
- }
- // tslint:disable-next-line:no-unnecessary-type-assertion
- const abiFunctionSignature = new AbiEncoder.Method(abiDefinition as MethodAbi).getSignature();
- if (abiFunctionSignature === functionSignature) {
- return true;
- }
- return false;
- }) as MethodAbi;
- return methodAbi;
- }
- protected _strictEncodeArguments(functionSignature: string, functionArguments: any): string {
- const abiEncoder = this._lookupAbiEncoder(functionSignature);
- const inputAbi = abiEncoder.getDataItem().components;
- if (inputAbi === undefined) {
- throw new Error(`Undefined Method Input ABI`);
- }
- const abiEncodedArguments = abiEncoder.encode(functionArguments);
- return abiEncodedArguments;
- }
- constructor(
- contractName: string,
- abi: ContractAbi,
- address: string,
- provider: Provider,
- txDefaults?: Partial<TxData>,
- ) {
- this.contractName = contractName;
- this._web3Wrapper = new Web3Wrapper(provider, txDefaults);
- this.abi = abi;
- this.address = address;
- const methodAbis = this.abi.filter(
- (abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Function,
- ) as MethodAbi[];
- this._abiEncoderByFunctionSignature = {};
- _.each(methodAbis, methodAbi => {
- const abiEncoder = new AbiEncoder.Method(methodAbi);
- const functionSignature = abiEncoder.getSignature();
- this._abiEncoderByFunctionSignature[functionSignature] = abiEncoder;
- });
- }
-}
diff --git a/packages/base-contract/src/utils.ts b/packages/base-contract/src/utils.ts
deleted file mode 100644
index 61f176df5..000000000
--- a/packages/base-contract/src/utils.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { DataItem } from 'ethereum-types';
-import * as _ from 'lodash';
-
-// tslint:disable-next-line:completed-docs
-export function formatABIDataItem(abi: DataItem, value: any, formatter: (type: string, value: any) => any): any {
- const trailingArrayRegex = /\[\d*\]$/;
- if (abi.type.match(trailingArrayRegex)) {
- const arrayItemType = abi.type.replace(trailingArrayRegex, '');
- return _.map(value, val => {
- const arrayItemAbi = {
- ...abi,
- type: arrayItemType,
- };
- return formatABIDataItem(arrayItemAbi, val, formatter);
- });
- } else if (abi.type === 'tuple') {
- const formattedTuple: { [componentName: string]: DataItem } = {};
- _.forEach(abi.components, componentABI => {
- formattedTuple[componentABI.name] = formatABIDataItem(componentABI, value[componentABI.name], formatter);
- });
- return formattedTuple;
- } else {
- return formatter(abi.type, value);
- }
-}
diff --git a/packages/base-contract/test/base_contract_test.ts b/packages/base-contract/test/base_contract_test.ts
deleted file mode 100644
index 2c31d1f11..000000000
--- a/packages/base-contract/test/base_contract_test.ts
+++ /dev/null
@@ -1,114 +0,0 @@
-import * as chai from 'chai';
-import 'mocha';
-
-import { BaseContract } from '../src';
-
-const { expect } = chai;
-
-describe('BaseContract', () => {
- describe('strictArgumentEncodingCheck', () => {
- it('works for simple types', () => {
- BaseContract.strictArgumentEncodingCheck(
- [{ name: 'to', type: 'address' }],
- ['0xe834ec434daba538cd1b9fe1582052b880bd7e63'],
- );
- });
- it('works for array types', () => {
- const inputAbi = [
- {
- name: 'takerAssetFillAmounts',
- type: 'uint256[]',
- },
- ];
- const args = [
- ['9000000000000000000', '79000000000000000000', '979000000000000000000', '7979000000000000000000'],
- ];
- BaseContract.strictArgumentEncodingCheck(inputAbi, args);
- });
- it('works for tuple/struct types', () => {
- const inputAbi = [
- {
- components: [
- {
- name: 'makerAddress',
- type: 'address',
- },
- {
- name: 'takerAddress',
- type: 'address',
- },
- {
- name: 'feeRecipientAddress',
- type: 'address',
- },
- {
- name: 'senderAddress',
- type: 'address',
- },
- {
- name: 'makerAssetAmount',
- type: 'uint256',
- },
- {
- name: 'takerAssetAmount',
- type: 'uint256',
- },
- {
- name: 'makerFee',
- type: 'uint256',
- },
- {
- name: 'takerFee',
- type: 'uint256',
- },
- {
- name: 'expirationTimeSeconds',
- type: 'uint256',
- },
- {
- name: 'salt',
- type: 'uint256',
- },
- {
- name: 'makerAssetData',
- type: 'bytes',
- },
- {
- name: 'takerAssetData',
- type: 'bytes',
- },
- ],
- name: 'order',
- type: 'tuple',
- },
- ];
- const args = [
- {
- makerAddress: '0x6ecbe1db9ef729cbe972c83fb886247691fb6beb',
- takerAddress: '0x0000000000000000000000000000000000000000',
- feeRecipientAddress: '0xe834ec434daba538cd1b9fe1582052b880bd7e63',
- senderAddress: '0x0000000000000000000000000000000000000000',
- makerAssetAmount: '0',
- takerAssetAmount: '200000000000000000000',
- makerFee: '1000000000000000000',
- takerFee: '1000000000000000000',
- expirationTimeSeconds: '1532563026',
- salt: '59342956082154660870994022243365949771115859664887449740907298019908621891376',
- makerAssetData: '0xf47261b00000000000000000000000001dc4c1cefef38a777b15aa20260a54e584b16c48',
- takerAssetData: '0xf47261b00000000000000000000000001d7022f5b17d2f8b695918fb48fa1089c9f85401',
- },
- ];
- BaseContract.strictArgumentEncodingCheck(inputAbi, args);
- });
- it('throws for integer overflows', () => {
- expect(() =>
- BaseContract.strictArgumentEncodingCheck([{ name: 'amount', type: 'uint8' }], ['256']),
- ).to.throw();
- });
- it('throws for fixed byte array overflows', () => {
- expect(() =>
- BaseContract.strictArgumentEncodingCheck([{ name: 'hash', type: 'bytes8' }], ['0x001122334455667788']),
- ).to.throw();
- });
- });
-});
diff --git a/packages/base-contract/test/utils_test.ts b/packages/base-contract/test/utils_test.ts
deleted file mode 100644
index 0608b72a2..000000000
--- a/packages/base-contract/test/utils_test.ts
+++ /dev/null
@@ -1,108 +0,0 @@
-import { BigNumber } from '@0x/utils';
-import * as chai from 'chai';
-import 'mocha';
-
-import { formatABIDataItem } from '../src/utils';
-
-const { expect } = chai;
-
-describe('Utils tests', () => {
- describe('#formatABIDataItem', () => {
- it('correctly handles arrays', () => {
- const calls: Array<{ type: string; value: any }> = [];
- const abi = {
- name: 'values',
- type: 'uint256[]',
- };
- const val = [1, 2, 3];
- const formatted = formatABIDataItem(abi, val, (type: string, value: any) => {
- calls.push({ type, value });
- return value; // no-op
- });
- expect(formatted).to.be.deep.equal(val);
- expect(calls).to.be.deep.equal([
- { type: 'uint256', value: 1 },
- { type: 'uint256', value: 2 },
- { type: 'uint256', value: 3 },
- ]);
- });
- it('correctly handles tuples', () => {
- const calls: Array<{ type: string; value: any }> = [];
- const abi = {
- components: [
- {
- name: 'to',
- type: 'address',
- },
- {
- name: 'amount',
- type: 'uint256',
- },
- ],
- name: 'data',
- type: 'tuple',
- };
- const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
- const val = { to: ZERO_ADDRESS, amount: new BigNumber(1) };
- const formatted = formatABIDataItem(abi, val, (type: string, value: any) => {
- calls.push({ type, value });
- return value; // no-op
- });
- expect(formatted).to.be.deep.equal(val);
- expect(calls).to.be.deep.equal([
- {
- type: 'address',
- value: val.to,
- },
- {
- type: 'uint256',
- value: val.amount,
- },
- ]);
- });
- it('correctly handles nested arrays of tuples', () => {
- const calls: Array<{ type: string; value: any }> = [];
- const abi = {
- components: [
- {
- name: 'to',
- type: 'address',
- },
- {
- name: 'amount',
- type: 'uint256',
- },
- ],
- name: 'data',
- type: 'tuple[2][]',
- };
- const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
- const val = [
- [{ to: ZERO_ADDRESS, amount: new BigNumber(1) }, { to: ZERO_ADDRESS, amount: new BigNumber(2) }],
- ];
- const formatted = formatABIDataItem(abi, val, (type: string, value: any) => {
- calls.push({ type, value });
- return value; // no-op
- });
- expect(formatted).to.be.deep.equal(val);
- expect(calls).to.be.deep.equal([
- {
- type: 'address',
- value: val[0][0].to,
- },
- {
- type: 'uint256',
- value: val[0][0].amount,
- },
- {
- type: 'address',
- value: val[0][1].to,
- },
- {
- type: 'uint256',
- value: val[0][1].amount,
- },
- ]);
- });
- });
-});
diff --git a/packages/base-contract/tsconfig.json b/packages/base-contract/tsconfig.json
deleted file mode 100644
index 718e623c7..000000000
--- a/packages/base-contract/tsconfig.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "extends": "../../tsconfig",
- "compilerOptions": {
- "outDir": "lib",
- "rootDir": "."
- },
- "include": ["src/**/*", "test/**/*"]
-}
diff --git a/packages/base-contract/tslint.json b/packages/base-contract/tslint.json
deleted file mode 100644
index dd9053357..000000000
--- a/packages/base-contract/tslint.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "extends": ["@0x/tslint-config"]
-}