diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2019-01-16 02:43:55 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2019-01-16 02:43:55 +0800 |
commit | 600b44c9620494c976b5aac6e8a1912543cda81c (patch) | |
tree | fd78c65dd2fdd7b1cbee1b5eff97a95a984a9186 /packages/base-contract | |
parent | 8a8a5332d76ae8429d1c6449e0ea693a2e8c8a8a (diff) | |
parent | f570f80674c22f69712c45e8e3c48e948b51f357 (diff) | |
download | dexon-sol-tools-600b44c9620494c976b5aac6e8a1912543cda81c.tar dexon-sol-tools-600b44c9620494c976b5aac6e8a1912543cda81c.tar.gz dexon-sol-tools-600b44c9620494c976b5aac6e8a1912543cda81c.tar.bz2 dexon-sol-tools-600b44c9620494c976b5aac6e8a1912543cda81c.tar.lz dexon-sol-tools-600b44c9620494c976b5aac6e8a1912543cda81c.tar.xz dexon-sol-tools-600b44c9620494c976b5aac6e8a1912543cda81c.tar.zst dexon-sol-tools-600b44c9620494c976b5aac6e8a1912543cda81c.zip |
Merge branch 'development' into feature/instant/asset-buyer-check-liquidity
Diffstat (limited to 'packages/base-contract')
-rw-r--r-- | packages/base-contract/CHANGELOG.json | 18 | ||||
-rw-r--r-- | packages/base-contract/CHANGELOG.md | 8 | ||||
-rw-r--r-- | packages/base-contract/package.json | 12 | ||||
-rw-r--r-- | packages/base-contract/src/index.ts | 55 |
4 files changed, 66 insertions, 27 deletions
diff --git a/packages/base-contract/CHANGELOG.json b/packages/base-contract/CHANGELOG.json index bd54400d3..68ebe8d9e 100644 --- a/packages/base-contract/CHANGELOG.json +++ b/packages/base-contract/CHANGELOG.json @@ -1,5 +1,23 @@ [ { + "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": [ diff --git a/packages/base-contract/CHANGELOG.md b/packages/base-contract/CHANGELOG.md index 7a1a96639..975a56fd4 100644 --- a/packages/base-contract/CHANGELOG.md +++ b/packages/base-contract/CHANGELOG.md @@ -5,6 +5,14 @@ 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 diff --git a/packages/base-contract/package.json b/packages/base-contract/package.json index 7193c4881..db09b16a1 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.13", "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.2", "@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.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" }, 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; }); } } |