diff options
Diffstat (limited to 'packages/base-contract')
-rw-r--r-- | packages/base-contract/CHANGELOG.json | 86 | ||||
-rw-r--r-- | packages/base-contract/CHANGELOG.md | 39 | ||||
-rw-r--r-- | packages/base-contract/README.md | 12 | ||||
-rw-r--r-- | packages/base-contract/package.json | 27 | ||||
-rw-r--r-- | packages/base-contract/src/index.ts | 35 | ||||
-rw-r--r-- | packages/base-contract/src/monorepo_scripts/postpublish.ts | 8 | ||||
-rw-r--r-- | packages/base-contract/test/utils_test.ts | 2 | ||||
-rw-r--r-- | packages/base-contract/tsconfig.json | 3 | ||||
-rw-r--r-- | packages/base-contract/tslint.json | 2 |
9 files changed, 171 insertions, 43 deletions
diff --git a/packages/base-contract/CHANGELOG.json b/packages/base-contract/CHANGELOG.json index 39e3cbe5e..166c04408 100644 --- a/packages/base-contract/CHANGELOG.json +++ b/packages/base-contract/CHANGELOG.json @@ -1,5 +1,91 @@ [ { + "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": [ { diff --git a/packages/base-contract/CHANGELOG.md b/packages/base-contract/CHANGELOG.md index 002ad931b..2981b5ef8 100644 --- a/packages/base-contract/CHANGELOG.md +++ b/packages/base-contract/CHANGELOG.md @@ -5,7 +5,44 @@ Edit the package's CHANGELOG.json file only. CHANGELOG -## v2.0.0-rc.1 - _August 13, 2018_ +## 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) diff --git a/packages/base-contract/README.md b/packages/base-contract/README.md index 4f2426c2e..b6ea05b74 100644 --- a/packages/base-contract/README.md +++ b/packages/base-contract/README.md @@ -1,25 +1,25 @@ -## @0xproject/base-contract +## @0x/base-contract BaseContract to derive all auto-generated wrappers from ## Installation ```bash -yarn add @0xproject/base-contract +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/@0xproject/typescript-typings/types", "node_modules/@types"], + "typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"], } ``` ## Usage ```javascript -import { BaseContract } from '@0xproject/base-contract'; +import { BaseContract } from '@0x/base-contract'; ``` ## Contributing @@ -47,13 +47,13 @@ yarn install To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: ```bash -PKG=@0xproject/base-contract yarn build +PKG=@0x/base-contract yarn build ``` Or continuously rebuild on change: ```bash -PKG=@0xproject/base-contract yarn watch +PKG=@0x/base-contract yarn watch ``` ### Lint diff --git a/packages/base-contract/package.json b/packages/base-contract/package.json index d31a02dda..520dff5f9 100644 --- a/packages/base-contract/package.json +++ b/packages/base-contract/package.json @@ -1,6 +1,6 @@ { - "name": "@0xproject/base-contract", - "version": "2.0.0-rc.1", + "name": "@0x/base-contract", + "version": "3.0.2", "engines": { "node": ">=6.12" }, @@ -8,17 +8,16 @@ "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "scripts": { - "watch_without_deps": "tsc -w", - "build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", - "clean": "shx rm -rf lib 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 --project . --exclude **/src/contract_wrappers/**/*", - "manual:postpublish": "yarn build; node ./scripts/postpublish.js" + "lint": "tslint --format stylish --project ." }, "license": "Apache-2.0", "repository": { @@ -30,11 +29,9 @@ }, "homepage": "https://github.com/0xProject/0x-monorepo/packages/base-contract/README.md", "devDependencies": { - "@0xproject/monorepo-scripts": "^1.0.5", - "@0xproject/tslint-config": "^1.0.5", + "@0x/tslint-config": "^1.0.9", "@types/lodash": "4.14.104", "chai": "^4.0.1", - "copyfiles": "^2.0.0", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", "npm-run-all": "^4.1.2", @@ -43,11 +40,11 @@ "typescript": "3.0.1" }, "dependencies": { - "@0xproject/typescript-typings": "^1.0.4", - "@0xproject/utils": "^1.0.5", - "@0xproject/web3-wrapper": "^1.2.0", - "ethereum-types": "^1.0.4", - "ethers": "3.0.22", + "@0x/typescript-typings": "^3.0.3", + "@0x/utils": "^2.0.3", + "@0x/web3-wrapper": "^3.1.0", + "ethereum-types": "^1.1.1", + "ethers": "~4.0.4", "lodash": "^4.17.5" }, "publishConfig": { diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 12f974445..fbb8478b7 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -1,5 +1,5 @@ -import { abiUtils, BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { abiUtils, BigNumber } from '@0x/utils'; +import { Web3Wrapper } from '@0x/web3-wrapper'; import { AbiDefinition, AbiType, @@ -17,9 +17,14 @@ import * as _ from 'lodash'; import { formatABIDataItem } from './utils'; export interface EthersInterfaceByFunctionSignature { - [key: string]: ethers.Interface; + [key: string]: ethers.utils.Interface; } +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 _ethersInterfacesByFunctionSignature: EthersInterfaceByFunctionSignature; protected _web3Wrapper: Web3Wrapper; @@ -61,7 +66,7 @@ export class BaseContract { } } protected static _bnToBigNumber(_type: string, value: any): any { - return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value; + return _.isObject(value) && value._hex ? new BigNumber(value.toString()) : value; } protected static async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>( txData: T, @@ -82,15 +87,24 @@ export class BaseContract { } return txDataWithDefaults; } + protected static _throwIfRevertWithReasonCallResult(rawCallResult: string): void { + if (rawCallResult.slice(REVERT_ERROR_SELECTOR_OFFSET, REVERT_ERROR_SELECTOR_END) === REVERT_ERROR_SELECTOR) { + const revertReason = ethers.utils.defaultAbiCoder.decode( + ['string'], + ethers.utils.hexDataSlice(rawCallResult, REVERT_ERROR_SELECTOR_BYTES_LENGTH), + ); + 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[]): void { - const coder = ethers.utils.AbiCoder.defaultCoder; + const coder = new ethers.utils.AbiCoder(); const params = abiUtils.parseEthersParams(inputAbi); - const rawEncoded = coder.encode(params.names, params.types, args); - const rawDecoded = coder.decode(params.names, params.types, rawEncoded); + const rawEncoded = coder.encode(inputAbi, args); + const rawDecoded = coder.decode(inputAbi, rawEncoded); for (let i = 0; i < rawDecoded.length; i++) { const original = args[i]; const decoded = rawDecoded[i]; @@ -103,7 +117,7 @@ export class BaseContract { } } } - protected _lookupEthersInterface(functionSignature: string): ethers.Interface { + protected _lookupEthersInterface(functionSignature: string): ethers.utils.Interface { const ethersInterface = this._ethersInterfacesByFunctionSignature[functionSignature]; if (_.isUndefined(ethersInterface)) { throw new Error(`Failed to lookup method with function signature '${functionSignature}'`); @@ -115,7 +129,8 @@ export class BaseContract { if (abiDefinition.type !== AbiType.Function) { return false; } - const abiFunctionSignature = abiUtils.getFunctionSignature(abiDefinition); + // tslint:disable-next-line:no-unnecessary-type-assertion + const abiFunctionSignature = abiUtils.getFunctionSignature(abiDefinition as MethodAbi); if (abiFunctionSignature === functionSignature) { return true; } @@ -140,7 +155,7 @@ export class BaseContract { this._ethersInterfacesByFunctionSignature = {}; _.each(methodAbis, methodAbi => { const functionSignature = abiUtils.getFunctionSignature(methodAbi); - this._ethersInterfacesByFunctionSignature[functionSignature] = new ethers.Interface([methodAbi]); + this._ethersInterfacesByFunctionSignature[functionSignature] = new ethers.utils.Interface([methodAbi]); }); } } diff --git a/packages/base-contract/src/monorepo_scripts/postpublish.ts b/packages/base-contract/src/monorepo_scripts/postpublish.ts deleted file mode 100644 index dcb99d0f7..000000000 --- a/packages/base-contract/src/monorepo_scripts/postpublish.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { postpublishUtils } from '@0xproject/monorepo-scripts'; - -import * as packageJSON from '../package.json'; -import * as tsConfigJSON from '../tsconfig.json'; - -const cwd = `${__dirname}/..`; -// tslint:disable-next-line:no-floating-promises -postpublishUtils.runAsync(packageJSON, tsConfigJSON, cwd); diff --git a/packages/base-contract/test/utils_test.ts b/packages/base-contract/test/utils_test.ts index c083704f4..0608b72a2 100644 --- a/packages/base-contract/test/utils_test.ts +++ b/packages/base-contract/test/utils_test.ts @@ -1,4 +1,4 @@ -import { BigNumber } from '@0xproject/utils'; +import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import 'mocha'; diff --git a/packages/base-contract/tsconfig.json b/packages/base-contract/tsconfig.json index 8b4cd47a2..718e623c7 100644 --- a/packages/base-contract/tsconfig.json +++ b/packages/base-contract/tsconfig.json @@ -1,7 +1,8 @@ { "extends": "../../tsconfig", "compilerOptions": { - "outDir": "lib" + "outDir": "lib", + "rootDir": "." }, "include": ["src/**/*", "test/**/*"] } diff --git a/packages/base-contract/tslint.json b/packages/base-contract/tslint.json index ffaefe83a..dd9053357 100644 --- a/packages/base-contract/tslint.json +++ b/packages/base-contract/tslint.json @@ -1,3 +1,3 @@ { - "extends": ["@0xproject/tslint-config"] + "extends": ["@0x/tslint-config"] } |