From 0fc356740aa59cdef0ec193a83468ef0f261ca6b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 1 Dec 2017 22:43:45 -0600 Subject: Add generated contract wrappers --- .../contract_wrappers/generated/base_contract.ts | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/0x.js/src/contract_wrappers/generated/base_contract.ts (limited to 'packages/0x.js/src/contract_wrappers/generated/base_contract.ts') diff --git a/packages/0x.js/src/contract_wrappers/generated/base_contract.ts b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts new file mode 100644 index 000000000..e5f536448 --- /dev/null +++ b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts @@ -0,0 +1,36 @@ +import * as _ from 'lodash'; +import * as Web3 from 'web3'; + +import {TxData, TxDataPayable} from '../../types'; + +// TODO: Gas Margin +// TODO: Abi check +export class BaseContract { + protected web3ContractInstance: Web3.ContractInstance; + protected defaults: Partial; + protected async applyDefaultsToTxDataAsync( + txData: T, + estimateGasAsync?: (txData: T) => Promise, + ): Promise { + // 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; + const txDataWithDefaults = { + ...removeUndefinedProperties(this.defaults), + ...removeUndefinedProperties(txData as any), + // HACK: TS can't prove that T is speadable. + // Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged + }; + if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) { + const estimatedGas = await estimateGasAsync(txData); + txDataWithDefaults.gas = estimatedGas; + } + return txDataWithDefaults; + } + constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial) { + this.web3ContractInstance = web3ContractInstance; + this.defaults = defaults; + } +} -- cgit v1.2.3