diff options
author | Fabio Berger <me@fabioberger.com> | 2019-01-15 22:13:24 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2019-01-15 22:13:24 +0800 |
commit | 7c37d10d1f93791db75b1622efa775a361965c49 (patch) | |
tree | 7017104bea27120661f71701552214dc5efba909 /packages/base-contract | |
parent | affd6170540034c31593a4f36ce1dbacb91b6b3e (diff) | |
parent | 18084588ea9fa724d6e32c9a49c79d49f189ba7c (diff) | |
download | dexon-sol-tools-7c37d10d1f93791db75b1622efa775a361965c49.tar dexon-sol-tools-7c37d10d1f93791db75b1622efa775a361965c49.tar.gz dexon-sol-tools-7c37d10d1f93791db75b1622efa775a361965c49.tar.bz2 dexon-sol-tools-7c37d10d1f93791db75b1622efa775a361965c49.tar.lz dexon-sol-tools-7c37d10d1f93791db75b1622efa775a361965c49.tar.xz dexon-sol-tools-7c37d10d1f93791db75b1622efa775a361965c49.tar.zst dexon-sol-tools-7c37d10d1f93791db75b1622efa775a361965c49.zip |
Merge branch 'development' into feature/monorepo-scripts/publishToDockerHub
* development: (87 commits)
Update packages/sol-tracing-utils/src/trace_collection_subprovider.ts
Make mapping namings direct
Remove unused tslint disable
Revert "Remove logAsyncErrors hack"
Remove logAsyncErrors hack
Refactor logAsyncErrors to follow our conventions
Export Sources and SourceCodes out of tracing utils
Replace console.log with logUtils.log (#1515)
strict decoding of return values using generics
makerAssetFillAmount -> takerAssetFillAmount
Ran prettier
Linter
Fix build after rebase
Style cleanup for Compressed Calldata in Contract Wrappers PR
Use simpler `_.find` to locate fillOrderBai
Updated dutch auction wrapper
Added back abi-gen-wrappers
Renamed signatureParser.ts to signature_parser.ts
Renamed decode rule `structsAsObjects` to `shouldConvertStructsToObjects`
circle build failed. New commit to resubmit job.
...
Diffstat (limited to 'packages/base-contract')
-rw-r--r-- | packages/base-contract/CHANGELOG.json | 9 | ||||
-rw-r--r-- | packages/base-contract/CHANGELOG.md | 4 | ||||
-rw-r--r-- | packages/base-contract/package.json | 12 | ||||
-rw-r--r-- | packages/base-contract/src/index.ts | 55 |
4 files changed, 53 insertions, 27 deletions
diff --git a/packages/base-contract/CHANGELOG.json b/packages/base-contract/CHANGELOG.json index bd54400d3..6c8f3b069 100644 --- a/packages/base-contract/CHANGELOG.json +++ b/packages/base-contract/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "timestamp": 1547225310, + "version": "3.0.12", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { "timestamp": 1547040760, "version": "3.0.11", "changes": [ diff --git a/packages/base-contract/CHANGELOG.md b/packages/base-contract/CHANGELOG.md index 7a1a96639..d99ea0c6e 100644 --- a/packages/base-contract/CHANGELOG.md +++ b/packages/base-contract/CHANGELOG.md @@ -5,6 +5,10 @@ Edit the package's CHANGELOG.json file only. CHANGELOG +## v3.0.12 - _January 11, 2019_ + + * Dependencies updated + ## v3.0.11 - _January 9, 2019_ * Dependencies updated diff --git a/packages/base-contract/package.json b/packages/base-contract/package.json index 7193c4881..027340508 100644 --- a/packages/base-contract/package.json +++ b/packages/base-contract/package.json @@ -1,6 +1,6 @@ { "name": "@0x/base-contract", - "version": "3.0.11", + "version": "3.0.12", "engines": { "node": ">=6.12" }, @@ -29,7 +29,7 @@ }, "homepage": "https://github.com/0xProject/0x-monorepo/packages/base-contract/README.md", "devDependencies": { - "@0x/tslint-config": "^2.0.0", + "@0x/tslint-config": "^2.0.1", "@types/lodash": "4.14.104", "chai": "^4.0.1", "make-promises-safe": "^1.1.0", @@ -40,10 +40,10 @@ "typescript": "3.0.1" }, "dependencies": { - "@0x/typescript-typings": "^3.0.6", - "@0x/utils": "^2.1.1", - "@0x/web3-wrapper": "^3.2.2", - "ethereum-types": "^1.1.4", + "@0x/typescript-typings": "^3.0.7", + "@0x/utils": "^3.0.0", + "@0x/web3-wrapper": "^3.2.3", + "ethereum-types": "^1.1.5", "ethers": "~4.0.4", "lodash": "^4.17.5" }, diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index fbb8478b7..c2b7b943b 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -1,4 +1,4 @@ -import { abiUtils, BigNumber } from '@0x/utils'; +import { AbiEncoder, abiUtils } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { AbiDefinition, @@ -16,8 +16,8 @@ import * as _ from 'lodash'; import { formatABIDataItem } from './utils'; -export interface EthersInterfaceByFunctionSignature { - [key: string]: ethers.utils.Interface; +export interface AbiEncoderByFunctionSignature { + [key: string]: AbiEncoder.Method; } const REVERT_ERROR_SELECTOR = '08c379a0'; @@ -26,7 +26,7 @@ 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 _abiEncoderByFunctionSignature: AbiEncoderByFunctionSignature; protected _web3Wrapper: Web3Wrapper; public abi: ContractAbi; public address: string; @@ -65,9 +65,6 @@ export class BaseContract { return defaultConstructorAbi; } } - protected static _bnToBigNumber(_type: string, value: any): any { - return _.isObject(value) && value._hex ? new BigNumber(value.toString()) : value; - } protected static async _applyDefaultsToTxDataAsync<T extends Partial<TxData | TxDataPayable>>( txData: T, txDefaults: Partial<TxData>, @@ -89,10 +86,15 @@ export class BaseContract { } 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'], + 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); } } @@ -100,11 +102,11 @@ export class BaseContract { // 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 = new ethers.utils.AbiCoder(); + public static strictArgumentEncodingCheck(inputAbi: DataItem[], args: any[]): string { + const abiEncoder = AbiEncoder.create(inputAbi); const params = abiUtils.parseEthersParams(inputAbi); - const rawEncoded = coder.encode(inputAbi, args); - const rawDecoded = coder.decode(inputAbi, rawEncoded); + 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]; @@ -116,13 +118,14 @@ export class BaseContract { ); } } + return rawEncoded; } - protected _lookupEthersInterface(functionSignature: string): ethers.utils.Interface { - const ethersInterface = this._ethersInterfacesByFunctionSignature[functionSignature]; - if (_.isUndefined(ethersInterface)) { + 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 ethersInterface; + return abiEncoder; } protected _lookupAbi(functionSignature: string): MethodAbi { const methodAbi = _.find(this.abi, (abiDefinition: AbiDefinition) => { @@ -130,7 +133,7 @@ export class BaseContract { return false; } // tslint:disable-next-line:no-unnecessary-type-assertion - const abiFunctionSignature = abiUtils.getFunctionSignature(abiDefinition as MethodAbi); + const abiFunctionSignature = new AbiEncoder.Method(abiDefinition as MethodAbi).getSignature(); if (abiFunctionSignature === functionSignature) { return true; } @@ -138,6 +141,15 @@ export class BaseContract { }) 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, @@ -152,10 +164,11 @@ export class BaseContract { const methodAbis = this.abi.filter( (abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Function, ) as MethodAbi[]; - this._ethersInterfacesByFunctionSignature = {}; + this._abiEncoderByFunctionSignature = {}; _.each(methodAbis, methodAbi => { - const functionSignature = abiUtils.getFunctionSignature(methodAbi); - this._ethersInterfacesByFunctionSignature[functionSignature] = new ethers.utils.Interface([methodAbi]); + const abiEncoder = new AbiEncoder.Method(methodAbi); + const functionSignature = abiEncoder.getSignature(); + this._abiEncoderByFunctionSignature[functionSignature] = abiEncoder; }); } } |