diff options
Diffstat (limited to 'packages/0x.js/src/contract_wrappers')
12 files changed, 2225 insertions, 15 deletions
diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 8c92931b4..5e5a38f8c 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -90,11 +90,13 @@ export class ContractWrapper { const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoop(log); return logWithDecodedArgs; } - protected async _instantiateContractIfExistsAsync<ContractType extends Web3.ContractInstance>( - artifact: Artifact, addressIfExists?: string): Promise<ContractType> { - const contractInstance = - await this._web3Wrapper.getContractInstanceFromArtifactAsync<ContractType>(artifact, addressIfExists); - return contractInstance; + protected async _instantiateContractIfExistsAsync( + artifact: Artifact, addressIfExists?: string, + ): Promise<Web3.ContractInstance> { + const web3ContractInstance = await this._web3Wrapper.getContractInstanceFromArtifactAsync( + artifact, addressIfExists, + ); + return web3ContractInstance; } protected _getContractAddress(artifact: Artifact, addressIfExists?: string): string { if (_.isUndefined(addressIfExists)) { diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts index ede0460bd..26025f6f9 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -2,11 +2,12 @@ import BigNumber from 'bignumber.js'; import * as _ from 'lodash'; import {artifacts} from '../artifacts'; -import {EtherTokenContract, TransactionOpts, ZeroExError} from '../types'; +import {TransactionOpts, ZeroExError} from '../types'; import {assert} from '../utils/assert'; import {Web3Wrapper} from '../web3_wrapper'; import {ContractWrapper} from './contract_wrapper'; +import {EtherTokenContract} from './generated/ether_token'; import {TokenWrapper} from './token_wrapper'; /** @@ -92,9 +93,10 @@ export class EtherTokenWrapper extends ContractWrapper { if (!_.isUndefined(this._etherTokenContractIfExists)) { return this._etherTokenContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync<EtherTokenContract>( + const web3ContractInstance = await this._instantiateContractIfExistsAsync( artifacts.EtherTokenArtifact, this._contractAddressIfExists, ); + const contractInstance = new EtherTokenContract(web3ContractInstance, this._web3Wrapper.getContractDefaults()); this._etherTokenContractIfExists = contractInstance; return this._etherTokenContractIfExists; } diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 273b348ff..aaf6256a3 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -9,7 +9,6 @@ import { DecodedLogArgs, ECSignature, EventCallback, - ExchangeContract, ExchangeContractErrCodes, ExchangeContractErrs, ExchangeContractEventArgs, @@ -40,6 +39,7 @@ import {utils} from '../utils/utils'; import {Web3Wrapper} from '../web3_wrapper'; import {ContractWrapper} from './contract_wrapper'; +import {ExchangeContract} from './generated/exchange'; import {TokenWrapper} from './token_wrapper'; const SHOULD_VALIDATE_BY_DEFAULT = true; @@ -789,9 +789,10 @@ export class ExchangeWrapper extends ContractWrapper { if (!_.isUndefined(this._exchangeContractIfExists)) { return this._exchangeContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync<ExchangeContract>( + const web3ContractInstance = await this._instantiateContractIfExistsAsync( artifacts.ExchangeArtifact, this._contractAddressIfExists, ); + const contractInstance = new ExchangeContract(web3ContractInstance, this._web3Wrapper.getContractDefaults()); this._exchangeContractIfExists = contractInstance; return this._exchangeContractIfExists; } 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..396a4d593 --- /dev/null +++ b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts @@ -0,0 +1,34 @@ +import * as _ from 'lodash'; +import * as Web3 from 'web3'; + +import {TxData, TxDataPayable} from '../../types'; + +export class BaseContract { + protected web3ContractInstance: Web3.ContractInstance; + protected defaults: Partial<TxData>; + protected async applyDefaultsToTxDataAsync<T extends TxData|TxDataPayable>( + txData: T, + 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; + const txDataWithDefaults = { + ...removeUndefinedProperties(this.defaults), + ...removeUndefinedProperties(txData as any), + // HACK: TS can't prove that T is spreadable. + // 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<TxData>) { + this.web3ContractInstance = web3ContractInstance; + this.defaults = defaults; + } +} diff --git a/packages/0x.js/src/contract_wrappers/generated/ether_token.ts b/packages/0x.js/src/contract_wrappers/generated/ether_token.ts new file mode 100644 index 000000000..eed5e4686 --- /dev/null +++ b/packages/0x.js/src/contract_wrappers/generated/ether_token.ts @@ -0,0 +1,363 @@ +/** + * This file is auto-generated using abi-gen. Don't edit directly. + * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates. + */ +import {BigNumber} from 'bignumber.js'; +import * as Web3 from 'web3'; + +import {TxData, TxDataPayable} from '../../types'; +import {classUtils} from '../../utils/class_utils'; +import {promisify} from '../../utils/promisify'; + +import {BaseContract} from './base_contract'; + +export class EtherTokenContract extends BaseContract { + public name = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as EtherTokenContract; + const result = await promisify<string + >( + self.web3ContractInstance.name.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public approve = { + async sendTransactionAsync( + _spender: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<string> { + const self = this as EtherTokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.approve.estimateGasAsync.bind( + self, + _spender, + _value, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.approve, self.web3ContractInstance, + )( + _spender, + _value, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _spender: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<number> { + const self = this as EtherTokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.approve.estimateGas, self.web3ContractInstance, + )( + _spender, + _value, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _spender: string, + _value: BigNumber, + txData: TxData = {}, + ): string { + const self = this as EtherTokenContract; + const abiEncodedTransactionData = self.web3ContractInstance.approve.getData(); + return abiEncodedTransactionData; + }, + }; + public totalSupply = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as EtherTokenContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.totalSupply.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public transferFrom = { + async sendTransactionAsync( + _from: string, + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<string> { + const self = this as EtherTokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.transferFrom.estimateGasAsync.bind( + self, + _from, + _to, + _value, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.transferFrom, self.web3ContractInstance, + )( + _from, + _to, + _value, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _from: string, + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<number> { + const self = this as EtherTokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.transferFrom.estimateGas, self.web3ContractInstance, + )( + _from, + _to, + _value, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _from: string, + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): string { + const self = this as EtherTokenContract; + const abiEncodedTransactionData = self.web3ContractInstance.transferFrom.getData(); + return abiEncodedTransactionData; + }, + }; + public withdraw = { + async sendTransactionAsync( + amount: BigNumber, + txData: TxData = {}, + ): Promise<string> { + const self = this as EtherTokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.withdraw.estimateGasAsync.bind( + self, + amount, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.withdraw, self.web3ContractInstance, + )( + amount, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + amount: BigNumber, + txData: TxData = {}, + ): Promise<number> { + const self = this as EtherTokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.withdraw.estimateGas, self.web3ContractInstance, + )( + amount, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + amount: BigNumber, + txData: TxData = {}, + ): string { + const self = this as EtherTokenContract; + const abiEncodedTransactionData = self.web3ContractInstance.withdraw.getData(); + return abiEncodedTransactionData; + }, + }; + public decimals = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as EtherTokenContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.decimals.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public balanceOf = { + async callAsync( + _owner: string, + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as EtherTokenContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.balanceOf.call, + self.web3ContractInstance, + )( + _owner, + ); + return result; + }, + }; + public symbol = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as EtherTokenContract; + const result = await promisify<string + >( + self.web3ContractInstance.symbol.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public transfer = { + async sendTransactionAsync( + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<string> { + const self = this as EtherTokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.transfer.estimateGasAsync.bind( + self, + _to, + _value, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.transfer, self.web3ContractInstance, + )( + _to, + _value, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<number> { + const self = this as EtherTokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.transfer.estimateGas, self.web3ContractInstance, + )( + _to, + _value, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): string { + const self = this as EtherTokenContract; + const abiEncodedTransactionData = self.web3ContractInstance.transfer.getData(); + return abiEncodedTransactionData; + }, + }; + public deposit = { + async sendTransactionAsync( + txData: TxDataPayable = {}, + ): Promise<string> { + const self = this as EtherTokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.deposit.estimateGasAsync.bind( + self, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.deposit, self.web3ContractInstance, + )( + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + txData: TxData = {}, + ): Promise<number> { + const self = this as EtherTokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.deposit.estimateGas, self.web3ContractInstance, + )( + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + txData: TxData = {}, + ): string { + const self = this as EtherTokenContract; + const abiEncodedTransactionData = self.web3ContractInstance.deposit.getData(); + return abiEncodedTransactionData; + }, + }; + public allowance = { + async callAsync( + _owner: string, + _spender: string, + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as EtherTokenContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.allowance.call, + self.web3ContractInstance, + )( + _owner, + _spender, + ); + return result; + }, + }; + constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) { + super(web3ContractInstance, defaults); + classUtils.bindAll(this, ['web3ContractInstance', 'defaults']); + } +} // tslint:disable:max-file-line-count diff --git a/packages/0x.js/src/contract_wrappers/generated/exchange.ts b/packages/0x.js/src/contract_wrappers/generated/exchange.ts new file mode 100644 index 000000000..8c25ca014 --- /dev/null +++ b/packages/0x.js/src/contract_wrappers/generated/exchange.ts @@ -0,0 +1,730 @@ +/** + * This file is auto-generated using abi-gen. Don't edit directly. + * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates. + */ +import {BigNumber} from 'bignumber.js'; +import * as Web3 from 'web3'; + +import {TxData, TxDataPayable} from '../../types'; +import {classUtils} from '../../utils/class_utils'; +import {promisify} from '../../utils/promisify'; + +import {BaseContract} from './base_contract'; + +export class ExchangeContract extends BaseContract { + public isRoundingError = { + async callAsync( + numerator: BigNumber, + denominator: BigNumber, + target: BigNumber, + defaultBlock?: Web3.BlockParam, + ): Promise<boolean + > { + const self = this as ExchangeContract; + const result = await promisify<boolean + >( + self.web3ContractInstance.isRoundingError.call, + self.web3ContractInstance, + )( + numerator, + denominator, + target, + ); + return result; + }, + }; + public filled = { + async callAsync( + index: string, + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as ExchangeContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.filled.call, + self.web3ContractInstance, + )( + index, + ); + return result; + }, + }; + public cancelled = { + async callAsync( + index: string, + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as ExchangeContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.cancelled.call, + self.web3ContractInstance, + )( + index, + ); + return result; + }, + }; + public fillOrdersUpTo = { + async sendTransactionAsync( + orderAddresses: string[][], + orderValues: BigNumber[][], + fillTakerTokenAmount: BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number|BigNumber[], + r: string[], + s: string[], + txData: TxData = {}, + ): Promise<string> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.fillOrdersUpTo.estimateGasAsync.bind( + self, + orderAddresses, + orderValues, + fillTakerTokenAmount, + shouldThrowOnInsufficientBalanceOrAllowance, + v, + r, + s, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.fillOrdersUpTo, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + fillTakerTokenAmount, + shouldThrowOnInsufficientBalanceOrAllowance, + v, + r, + s, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + orderAddresses: string[][], + orderValues: BigNumber[][], + fillTakerTokenAmount: BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number|BigNumber[], + r: string[], + s: string[], + txData: TxData = {}, + ): Promise<number> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.fillOrdersUpTo.estimateGas, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + fillTakerTokenAmount, + shouldThrowOnInsufficientBalanceOrAllowance, + v, + r, + s, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + orderAddresses: string[][], + orderValues: BigNumber[][], + fillTakerTokenAmount: BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number|BigNumber[], + r: string[], + s: string[], + txData: TxData = {}, + ): string { + const self = this as ExchangeContract; + const abiEncodedTransactionData = self.web3ContractInstance.fillOrdersUpTo.getData(); + return abiEncodedTransactionData; + }, + }; + public cancelOrder = { + async sendTransactionAsync( + orderAddresses: string[], + orderValues: BigNumber[], + cancelTakerTokenAmount: BigNumber, + txData: TxData = {}, + ): Promise<string> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.cancelOrder.estimateGasAsync.bind( + self, + orderAddresses, + orderValues, + cancelTakerTokenAmount, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.cancelOrder, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + cancelTakerTokenAmount, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + orderAddresses: string[], + orderValues: BigNumber[], + cancelTakerTokenAmount: BigNumber, + txData: TxData = {}, + ): Promise<number> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.cancelOrder.estimateGas, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + cancelTakerTokenAmount, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + orderAddresses: string[], + orderValues: BigNumber[], + cancelTakerTokenAmount: BigNumber, + txData: TxData = {}, + ): string { + const self = this as ExchangeContract; + const abiEncodedTransactionData = self.web3ContractInstance.cancelOrder.getData(); + return abiEncodedTransactionData; + }, + }; + public ZRX_TOKEN_CONTRACT = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as ExchangeContract; + const result = await promisify<string + >( + self.web3ContractInstance.ZRX_TOKEN_CONTRACT.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public batchFillOrKillOrders = { + async sendTransactionAsync( + orderAddresses: string[][], + orderValues: BigNumber[][], + fillTakerTokenAmounts: BigNumber[], + v: number|BigNumber[], + r: string[], + s: string[], + txData: TxData = {}, + ): Promise<string> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.batchFillOrKillOrders.estimateGasAsync.bind( + self, + orderAddresses, + orderValues, + fillTakerTokenAmounts, + v, + r, + s, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.batchFillOrKillOrders, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + fillTakerTokenAmounts, + v, + r, + s, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + orderAddresses: string[][], + orderValues: BigNumber[][], + fillTakerTokenAmounts: BigNumber[], + v: number|BigNumber[], + r: string[], + s: string[], + txData: TxData = {}, + ): Promise<number> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.batchFillOrKillOrders.estimateGas, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + fillTakerTokenAmounts, + v, + r, + s, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + orderAddresses: string[][], + orderValues: BigNumber[][], + fillTakerTokenAmounts: BigNumber[], + v: number|BigNumber[], + r: string[], + s: string[], + txData: TxData = {}, + ): string { + const self = this as ExchangeContract; + const abiEncodedTransactionData = self.web3ContractInstance.batchFillOrKillOrders.getData(); + return abiEncodedTransactionData; + }, + }; + public fillOrKillOrder = { + async sendTransactionAsync( + orderAddresses: string[], + orderValues: BigNumber[], + fillTakerTokenAmount: BigNumber, + v: number|BigNumber, + r: string, + s: string, + txData: TxData = {}, + ): Promise<string> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.fillOrKillOrder.estimateGasAsync.bind( + self, + orderAddresses, + orderValues, + fillTakerTokenAmount, + v, + r, + s, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.fillOrKillOrder, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + fillTakerTokenAmount, + v, + r, + s, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + orderAddresses: string[], + orderValues: BigNumber[], + fillTakerTokenAmount: BigNumber, + v: number|BigNumber, + r: string, + s: string, + txData: TxData = {}, + ): Promise<number> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.fillOrKillOrder.estimateGas, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + fillTakerTokenAmount, + v, + r, + s, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + orderAddresses: string[], + orderValues: BigNumber[], + fillTakerTokenAmount: BigNumber, + v: number|BigNumber, + r: string, + s: string, + txData: TxData = {}, + ): string { + const self = this as ExchangeContract; + const abiEncodedTransactionData = self.web3ContractInstance.fillOrKillOrder.getData(); + return abiEncodedTransactionData; + }, + }; + public getUnavailableTakerTokenAmount = { + async callAsync( + orderHash: string, + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as ExchangeContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.getUnavailableTakerTokenAmount.call, + self.web3ContractInstance, + )( + orderHash, + ); + return result; + }, + }; + public isValidSignature = { + async callAsync( + signer: string, + hash: string, + v: number|BigNumber, + r: string, + s: string, + defaultBlock?: Web3.BlockParam, + ): Promise<boolean + > { + const self = this as ExchangeContract; + const result = await promisify<boolean + >( + self.web3ContractInstance.isValidSignature.call, + self.web3ContractInstance, + )( + signer, + hash, + v, + r, + s, + ); + return result; + }, + }; + public getPartialAmount = { + async callAsync( + numerator: BigNumber, + denominator: BigNumber, + target: BigNumber, + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as ExchangeContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.getPartialAmount.call, + self.web3ContractInstance, + )( + numerator, + denominator, + target, + ); + return result; + }, + }; + public TOKEN_TRANSFER_PROXY_CONTRACT = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as ExchangeContract; + const result = await promisify<string + >( + self.web3ContractInstance.TOKEN_TRANSFER_PROXY_CONTRACT.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public batchFillOrders = { + async sendTransactionAsync( + orderAddresses: string[][], + orderValues: BigNumber[][], + fillTakerTokenAmounts: BigNumber[], + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number|BigNumber[], + r: string[], + s: string[], + txData: TxData = {}, + ): Promise<string> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.batchFillOrders.estimateGasAsync.bind( + self, + orderAddresses, + orderValues, + fillTakerTokenAmounts, + shouldThrowOnInsufficientBalanceOrAllowance, + v, + r, + s, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.batchFillOrders, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + fillTakerTokenAmounts, + shouldThrowOnInsufficientBalanceOrAllowance, + v, + r, + s, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + orderAddresses: string[][], + orderValues: BigNumber[][], + fillTakerTokenAmounts: BigNumber[], + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number|BigNumber[], + r: string[], + s: string[], + txData: TxData = {}, + ): Promise<number> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.batchFillOrders.estimateGas, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + fillTakerTokenAmounts, + shouldThrowOnInsufficientBalanceOrAllowance, + v, + r, + s, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + orderAddresses: string[][], + orderValues: BigNumber[][], + fillTakerTokenAmounts: BigNumber[], + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number|BigNumber[], + r: string[], + s: string[], + txData: TxData = {}, + ): string { + const self = this as ExchangeContract; + const abiEncodedTransactionData = self.web3ContractInstance.batchFillOrders.getData(); + return abiEncodedTransactionData; + }, + }; + public batchCancelOrders = { + async sendTransactionAsync( + orderAddresses: string[][], + orderValues: BigNumber[][], + cancelTakerTokenAmounts: BigNumber[], + txData: TxData = {}, + ): Promise<string> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.batchCancelOrders.estimateGasAsync.bind( + self, + orderAddresses, + orderValues, + cancelTakerTokenAmounts, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.batchCancelOrders, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + cancelTakerTokenAmounts, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + orderAddresses: string[][], + orderValues: BigNumber[][], + cancelTakerTokenAmounts: BigNumber[], + txData: TxData = {}, + ): Promise<number> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.batchCancelOrders.estimateGas, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + cancelTakerTokenAmounts, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + orderAddresses: string[][], + orderValues: BigNumber[][], + cancelTakerTokenAmounts: BigNumber[], + txData: TxData = {}, + ): string { + const self = this as ExchangeContract; + const abiEncodedTransactionData = self.web3ContractInstance.batchCancelOrders.getData(); + return abiEncodedTransactionData; + }, + }; + public fillOrder = { + async sendTransactionAsync( + orderAddresses: string[], + orderValues: BigNumber[], + fillTakerTokenAmount: BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number|BigNumber, + r: string, + s: string, + txData: TxData = {}, + ): Promise<string> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.fillOrder.estimateGasAsync.bind( + self, + orderAddresses, + orderValues, + fillTakerTokenAmount, + shouldThrowOnInsufficientBalanceOrAllowance, + v, + r, + s, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.fillOrder, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + fillTakerTokenAmount, + shouldThrowOnInsufficientBalanceOrAllowance, + v, + r, + s, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + orderAddresses: string[], + orderValues: BigNumber[], + fillTakerTokenAmount: BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number|BigNumber, + r: string, + s: string, + txData: TxData = {}, + ): Promise<number> { + const self = this as ExchangeContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.fillOrder.estimateGas, self.web3ContractInstance, + )( + orderAddresses, + orderValues, + fillTakerTokenAmount, + shouldThrowOnInsufficientBalanceOrAllowance, + v, + r, + s, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + orderAddresses: string[], + orderValues: BigNumber[], + fillTakerTokenAmount: BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number|BigNumber, + r: string, + s: string, + txData: TxData = {}, + ): string { + const self = this as ExchangeContract; + const abiEncodedTransactionData = self.web3ContractInstance.fillOrder.getData(); + return abiEncodedTransactionData; + }, + }; + public getOrderHash = { + async callAsync( + orderAddresses: string[], + orderValues: BigNumber[], + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as ExchangeContract; + const result = await promisify<string + >( + self.web3ContractInstance.getOrderHash.call, + self.web3ContractInstance, + )( + orderAddresses, + orderValues, + ); + return result; + }, + }; + public EXTERNAL_QUERY_GAS_LIMIT = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as ExchangeContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.EXTERNAL_QUERY_GAS_LIMIT.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public VERSION = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as ExchangeContract; + const result = await promisify<string + >( + self.web3ContractInstance.VERSION.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) { + super(web3ContractInstance, defaults); + classUtils.bindAll(this, ['web3ContractInstance', 'defaults']); + } +} // tslint:disable:max-file-line-count diff --git a/packages/0x.js/src/contract_wrappers/generated/token.ts b/packages/0x.js/src/contract_wrappers/generated/token.ts new file mode 100644 index 000000000..30b06292f --- /dev/null +++ b/packages/0x.js/src/contract_wrappers/generated/token.ts @@ -0,0 +1,232 @@ +/** + * This file is auto-generated using abi-gen. Don't edit directly. + * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates. + */ +import {BigNumber} from 'bignumber.js'; +import * as Web3 from 'web3'; + +import {TxData, TxDataPayable} from '../../types'; +import {classUtils} from '../../utils/class_utils'; +import {promisify} from '../../utils/promisify'; + +import {BaseContract} from './base_contract'; + +export class TokenContract extends BaseContract { + public approve = { + async sendTransactionAsync( + _spender: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.approve.estimateGasAsync.bind( + self, + _spender, + _value, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.approve, self.web3ContractInstance, + )( + _spender, + _value, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _spender: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.approve.estimateGas, self.web3ContractInstance, + )( + _spender, + _value, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _spender: string, + _value: BigNumber, + txData: TxData = {}, + ): string { + const self = this as TokenContract; + const abiEncodedTransactionData = self.web3ContractInstance.approve.getData(); + return abiEncodedTransactionData; + }, + }; + public totalSupply = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as TokenContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.totalSupply.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public transferFrom = { + async sendTransactionAsync( + _from: string, + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.transferFrom.estimateGasAsync.bind( + self, + _from, + _to, + _value, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.transferFrom, self.web3ContractInstance, + )( + _from, + _to, + _value, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _from: string, + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.transferFrom.estimateGas, self.web3ContractInstance, + )( + _from, + _to, + _value, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _from: string, + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): string { + const self = this as TokenContract; + const abiEncodedTransactionData = self.web3ContractInstance.transferFrom.getData(); + return abiEncodedTransactionData; + }, + }; + public balanceOf = { + async callAsync( + _owner: string, + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as TokenContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.balanceOf.call, + self.web3ContractInstance, + )( + _owner, + ); + return result; + }, + }; + public transfer = { + async sendTransactionAsync( + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.transfer.estimateGasAsync.bind( + self, + _to, + _value, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.transfer, self.web3ContractInstance, + )( + _to, + _value, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.transfer.estimateGas, self.web3ContractInstance, + )( + _to, + _value, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _to: string, + _value: BigNumber, + txData: TxData = {}, + ): string { + const self = this as TokenContract; + const abiEncodedTransactionData = self.web3ContractInstance.transfer.getData(); + return abiEncodedTransactionData; + }, + }; + public allowance = { + async callAsync( + _owner: string, + _spender: string, + defaultBlock?: Web3.BlockParam, + ): Promise<BigNumber + > { + const self = this as TokenContract; + const result = await promisify<BigNumber + >( + self.web3ContractInstance.allowance.call, + self.web3ContractInstance, + )( + _owner, + _spender, + ); + return result; + }, + }; + constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) { + super(web3ContractInstance, defaults); + classUtils.bindAll(this, ['web3ContractInstance', 'defaults']); + } +} // tslint:disable:max-file-line-count diff --git a/packages/0x.js/src/contract_wrappers/generated/token_registry.ts b/packages/0x.js/src/contract_wrappers/generated/token_registry.ts new file mode 100644 index 000000000..6aacc4336 --- /dev/null +++ b/packages/0x.js/src/contract_wrappers/generated/token_registry.ts @@ -0,0 +1,550 @@ +/** + * This file is auto-generated using abi-gen. Don't edit directly. + * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates. + */ +import {BigNumber} from 'bignumber.js'; +import * as Web3 from 'web3'; + +import {TxData, TxDataPayable} from '../../types'; +import {classUtils} from '../../utils/class_utils'; +import {promisify} from '../../utils/promisify'; + +import {BaseContract} from './base_contract'; + +export class TokenRegistryContract extends BaseContract { + public removeToken = { + async sendTransactionAsync( + _token: string, + _index: BigNumber, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.removeToken.estimateGasAsync.bind( + self, + _token, + _index, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.removeToken, self.web3ContractInstance, + )( + _token, + _index, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _token: string, + _index: BigNumber, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.removeToken.estimateGas, self.web3ContractInstance, + )( + _token, + _index, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _token: string, + _index: BigNumber, + txData: TxData = {}, + ): string { + const self = this as TokenRegistryContract; + const abiEncodedTransactionData = self.web3ContractInstance.removeToken.getData(); + return abiEncodedTransactionData; + }, + }; + public getTokenAddressByName = { + async callAsync( + _name: string, + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as TokenRegistryContract; + const result = await promisify<string + >( + self.web3ContractInstance.getTokenAddressByName.call, + self.web3ContractInstance, + )( + _name, + ); + return result; + }, + }; + public getTokenAddressBySymbol = { + async callAsync( + _symbol: string, + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as TokenRegistryContract; + const result = await promisify<string + >( + self.web3ContractInstance.getTokenAddressBySymbol.call, + self.web3ContractInstance, + )( + _symbol, + ); + return result; + }, + }; + public setTokenSwarmHash = { + async sendTransactionAsync( + _token: string, + _swarmHash: string, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.setTokenSwarmHash.estimateGasAsync.bind( + self, + _token, + _swarmHash, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.setTokenSwarmHash, self.web3ContractInstance, + )( + _token, + _swarmHash, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _token: string, + _swarmHash: string, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.setTokenSwarmHash.estimateGas, self.web3ContractInstance, + )( + _token, + _swarmHash, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _token: string, + _swarmHash: string, + txData: TxData = {}, + ): string { + const self = this as TokenRegistryContract; + const abiEncodedTransactionData = self.web3ContractInstance.setTokenSwarmHash.getData(); + return abiEncodedTransactionData; + }, + }; + public getTokenMetaData = { + async callAsync( + _token: string, + defaultBlock?: Web3.BlockParam, + ): Promise<[string, string, string, BigNumber, string, string] + > { + const self = this as TokenRegistryContract; + const result = await promisify<[string, string, string, BigNumber, string, string] + >( + self.web3ContractInstance.getTokenMetaData.call, + self.web3ContractInstance, + )( + _token, + ); + return result; + }, + }; + public owner = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as TokenRegistryContract; + const result = await promisify<string + >( + self.web3ContractInstance.owner.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public addToken = { + async sendTransactionAsync( + _token: string, + _name: string, + _symbol: string, + _decimals: number|BigNumber, + _ipfsHash: string, + _swarmHash: string, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.addToken.estimateGasAsync.bind( + self, + _token, + _name, + _symbol, + _decimals, + _ipfsHash, + _swarmHash, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.addToken, self.web3ContractInstance, + )( + _token, + _name, + _symbol, + _decimals, + _ipfsHash, + _swarmHash, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _token: string, + _name: string, + _symbol: string, + _decimals: number|BigNumber, + _ipfsHash: string, + _swarmHash: string, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.addToken.estimateGas, self.web3ContractInstance, + )( + _token, + _name, + _symbol, + _decimals, + _ipfsHash, + _swarmHash, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _token: string, + _name: string, + _symbol: string, + _decimals: number|BigNumber, + _ipfsHash: string, + _swarmHash: string, + txData: TxData = {}, + ): string { + const self = this as TokenRegistryContract; + const abiEncodedTransactionData = self.web3ContractInstance.addToken.getData(); + return abiEncodedTransactionData; + }, + }; + public setTokenName = { + async sendTransactionAsync( + _token: string, + _name: string, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.setTokenName.estimateGasAsync.bind( + self, + _token, + _name, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.setTokenName, self.web3ContractInstance, + )( + _token, + _name, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _token: string, + _name: string, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.setTokenName.estimateGas, self.web3ContractInstance, + )( + _token, + _name, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _token: string, + _name: string, + txData: TxData = {}, + ): string { + const self = this as TokenRegistryContract; + const abiEncodedTransactionData = self.web3ContractInstance.setTokenName.getData(); + return abiEncodedTransactionData; + }, + }; + public tokens = { + async callAsync( + index: string, + defaultBlock?: Web3.BlockParam, + ): Promise<[string, string, string, BigNumber, string, string] + > { + const self = this as TokenRegistryContract; + const result = await promisify<[string, string, string, BigNumber, string, string] + >( + self.web3ContractInstance.tokens.call, + self.web3ContractInstance, + )( + index, + ); + return result; + }, + }; + public tokenAddresses = { + async callAsync( + index: BigNumber, + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as TokenRegistryContract; + const result = await promisify<string + >( + self.web3ContractInstance.tokenAddresses.call, + self.web3ContractInstance, + )( + index, + ); + return result; + }, + }; + public getTokenByName = { + async callAsync( + _name: string, + defaultBlock?: Web3.BlockParam, + ): Promise<[string, string, string, BigNumber, string, string] + > { + const self = this as TokenRegistryContract; + const result = await promisify<[string, string, string, BigNumber, string, string] + >( + self.web3ContractInstance.getTokenByName.call, + self.web3ContractInstance, + )( + _name, + ); + return result; + }, + }; + public getTokenAddresses = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<string[] + > { + const self = this as TokenRegistryContract; + const result = await promisify<string[] + >( + self.web3ContractInstance.getTokenAddresses.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public setTokenIpfsHash = { + async sendTransactionAsync( + _token: string, + _ipfsHash: string, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.setTokenIpfsHash.estimateGasAsync.bind( + self, + _token, + _ipfsHash, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.setTokenIpfsHash, self.web3ContractInstance, + )( + _token, + _ipfsHash, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _token: string, + _ipfsHash: string, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.setTokenIpfsHash.estimateGas, self.web3ContractInstance, + )( + _token, + _ipfsHash, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _token: string, + _ipfsHash: string, + txData: TxData = {}, + ): string { + const self = this as TokenRegistryContract; + const abiEncodedTransactionData = self.web3ContractInstance.setTokenIpfsHash.getData(); + return abiEncodedTransactionData; + }, + }; + public getTokenBySymbol = { + async callAsync( + _symbol: string, + defaultBlock?: Web3.BlockParam, + ): Promise<[string, string, string, BigNumber, string, string] + > { + const self = this as TokenRegistryContract; + const result = await promisify<[string, string, string, BigNumber, string, string] + >( + self.web3ContractInstance.getTokenBySymbol.call, + self.web3ContractInstance, + )( + _symbol, + ); + return result; + }, + }; + public setTokenSymbol = { + async sendTransactionAsync( + _token: string, + _symbol: string, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.setTokenSymbol.estimateGasAsync.bind( + self, + _token, + _symbol, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.setTokenSymbol, self.web3ContractInstance, + )( + _token, + _symbol, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + _token: string, + _symbol: string, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.setTokenSymbol.estimateGas, self.web3ContractInstance, + )( + _token, + _symbol, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + _token: string, + _symbol: string, + txData: TxData = {}, + ): string { + const self = this as TokenRegistryContract; + const abiEncodedTransactionData = self.web3ContractInstance.setTokenSymbol.getData(); + return abiEncodedTransactionData; + }, + }; + public transferOwnership = { + async sendTransactionAsync( + newOwner: string, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.transferOwnership.estimateGasAsync.bind( + self, + newOwner, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.transferOwnership, self.web3ContractInstance, + )( + newOwner, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + newOwner: string, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenRegistryContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.transferOwnership.estimateGas, self.web3ContractInstance, + )( + newOwner, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + newOwner: string, + txData: TxData = {}, + ): string { + const self = this as TokenRegistryContract; + const abiEncodedTransactionData = self.web3ContractInstance.transferOwnership.getData(); + return abiEncodedTransactionData; + }, + }; + constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) { + super(web3ContractInstance, defaults); + classUtils.bindAll(this, ['web3ContractInstance', 'defaults']); + } +} // tslint:disable:max-file-line-count diff --git a/packages/0x.js/src/contract_wrappers/generated/token_transfer_proxy.ts b/packages/0x.js/src/contract_wrappers/generated/token_transfer_proxy.ts new file mode 100644 index 000000000..50f1c8f25 --- /dev/null +++ b/packages/0x.js/src/contract_wrappers/generated/token_transfer_proxy.ts @@ -0,0 +1,285 @@ +/** + * This file is auto-generated using abi-gen. Don't edit directly. + * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates. + */ +import {BigNumber} from 'bignumber.js'; +import * as Web3 from 'web3'; + +import {TxData, TxDataPayable} from '../../types'; +import {classUtils} from '../../utils/class_utils'; +import {promisify} from '../../utils/promisify'; + +import {BaseContract} from './base_contract'; + +export class TokenTransferProxyContract extends BaseContract { + public transferFrom = { + async sendTransactionAsync( + token: string, + from: string, + to: string, + value: BigNumber, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenTransferProxyContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.transferFrom.estimateGasAsync.bind( + self, + token, + from, + to, + value, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.transferFrom, self.web3ContractInstance, + )( + token, + from, + to, + value, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + token: string, + from: string, + to: string, + value: BigNumber, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenTransferProxyContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.transferFrom.estimateGas, self.web3ContractInstance, + )( + token, + from, + to, + value, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + token: string, + from: string, + to: string, + value: BigNumber, + txData: TxData = {}, + ): string { + const self = this as TokenTransferProxyContract; + const abiEncodedTransactionData = self.web3ContractInstance.transferFrom.getData(); + return abiEncodedTransactionData; + }, + }; + public addAuthorizedAddress = { + async sendTransactionAsync( + target: string, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenTransferProxyContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.addAuthorizedAddress.estimateGasAsync.bind( + self, + target, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.addAuthorizedAddress, self.web3ContractInstance, + )( + target, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + target: string, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenTransferProxyContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.addAuthorizedAddress.estimateGas, self.web3ContractInstance, + )( + target, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + target: string, + txData: TxData = {}, + ): string { + const self = this as TokenTransferProxyContract; + const abiEncodedTransactionData = self.web3ContractInstance.addAuthorizedAddress.getData(); + return abiEncodedTransactionData; + }, + }; + public authorities = { + async callAsync( + index: BigNumber, + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as TokenTransferProxyContract; + const result = await promisify<string + >( + self.web3ContractInstance.authorities.call, + self.web3ContractInstance, + )( + index, + ); + return result; + }, + }; + public removeAuthorizedAddress = { + async sendTransactionAsync( + target: string, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenTransferProxyContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.removeAuthorizedAddress.estimateGasAsync.bind( + self, + target, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.removeAuthorizedAddress, self.web3ContractInstance, + )( + target, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + target: string, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenTransferProxyContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.removeAuthorizedAddress.estimateGas, self.web3ContractInstance, + )( + target, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + target: string, + txData: TxData = {}, + ): string { + const self = this as TokenTransferProxyContract; + const abiEncodedTransactionData = self.web3ContractInstance.removeAuthorizedAddress.getData(); + return abiEncodedTransactionData; + }, + }; + public owner = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<string + > { + const self = this as TokenTransferProxyContract; + const result = await promisify<string + >( + self.web3ContractInstance.owner.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public authorized = { + async callAsync( + index: string, + defaultBlock?: Web3.BlockParam, + ): Promise<boolean + > { + const self = this as TokenTransferProxyContract; + const result = await promisify<boolean + >( + self.web3ContractInstance.authorized.call, + self.web3ContractInstance, + )( + index, + ); + return result; + }, + }; + public getAuthorizedAddresses = { + async callAsync( + defaultBlock?: Web3.BlockParam, + ): Promise<string[] + > { + const self = this as TokenTransferProxyContract; + const result = await promisify<string[] + >( + self.web3ContractInstance.getAuthorizedAddresses.call, + self.web3ContractInstance, + )( + ); + return result; + }, + }; + public transferOwnership = { + async sendTransactionAsync( + newOwner: string, + txData: TxData = {}, + ): Promise<string> { + const self = this as TokenTransferProxyContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + self.transferOwnership.estimateGasAsync.bind( + self, + newOwner, + ), + ); + const txHash = await promisify<string>( + self.web3ContractInstance.transferOwnership, self.web3ContractInstance, + )( + newOwner, + txDataWithDefaults, + ); + return txHash; + }, + async estimateGasAsync( + newOwner: string, + txData: TxData = {}, + ): Promise<number> { + const self = this as TokenTransferProxyContract; + const txDataWithDefaults = await self.applyDefaultsToTxDataAsync( + txData, + ); + const gas = await promisify<number>( + self.web3ContractInstance.transferOwnership.estimateGas, self.web3ContractInstance, + )( + newOwner, + txDataWithDefaults, + ); + return gas; + }, + getABIEncodedTransactionData( + newOwner: string, + txData: TxData = {}, + ): string { + const self = this as TokenTransferProxyContract; + const abiEncodedTransactionData = self.web3ContractInstance.transferOwnership.getData(); + return abiEncodedTransactionData; + }, + }; + constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) { + super(web3ContractInstance, defaults); + classUtils.bindAll(this, ['web3ContractInstance', 'defaults']); + } +} // tslint:disable:max-file-line-count diff --git a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts index 35337fa35..27ecb8bde 100644 --- a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts @@ -1,12 +1,13 @@ import * as _ from 'lodash'; import {artifacts} from '../artifacts'; -import {Token, TokenMetadata, TokenRegistryContract, ZeroExError} from '../types'; +import {Token, TokenMetadata, ZeroExError} from '../types'; import {assert} from '../utils/assert'; import {constants} from '../utils/constants'; import {Web3Wrapper} from '../web3_wrapper'; import {ContractWrapper} from './contract_wrapper'; +import {TokenRegistryContract} from './generated/token_registry'; /** * This class includes all the functionality related to interacting with the 0x Token Registry smart contract. @@ -116,9 +117,12 @@ export class TokenRegistryWrapper extends ContractWrapper { if (!_.isUndefined(this._tokenRegistryContractIfExists)) { return this._tokenRegistryContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync<TokenRegistryContract>( + const web3ContractInstance = await this._instantiateContractIfExistsAsync( artifacts.TokenRegistryArtifact, this._contractAddressIfExists, ); + const contractInstance = new TokenRegistryContract( + web3ContractInstance, this._web3Wrapper.getContractDefaults(), + ); this._tokenRegistryContractIfExists = contractInstance; return this._tokenRegistryContractIfExists; } diff --git a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts index c3df7d3eb..edc702672 100644 --- a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts @@ -1,10 +1,11 @@ import * as _ from 'lodash'; import {artifacts} from '../artifacts'; -import {TokenTransferProxyContract, ZeroExError} from '../types'; +import {ZeroExError} from '../types'; import {Web3Wrapper} from '../web3_wrapper'; import {ContractWrapper} from './contract_wrapper'; +import {TokenTransferProxyContract} from './generated/token_transfer_proxy'; /** * This class includes the functionality related to interacting with the TokenTransferProxy contract. @@ -53,9 +54,12 @@ export class TokenTransferProxyWrapper extends ContractWrapper { if (!_.isUndefined(this._tokenTransferProxyContractIfExists)) { return this._tokenTransferProxyContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync<TokenTransferProxyContract>( + const web3ContractInstance = await this._instantiateContractIfExistsAsync( artifacts.TokenTransferProxyArtifact, this._contractAddressIfExists, ); + const contractInstance = new TokenTransferProxyContract( + web3ContractInstance, this._web3Wrapper.getContractDefaults(), + ); this._tokenTransferProxyContractIfExists = contractInstance; return this._tokenTransferProxyContractIfExists; } diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts index 4a1dfcf8d..630ab6e3b 100644 --- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts @@ -9,7 +9,6 @@ import { LogWithDecodedArgs, MethodOpts, SubscriptionOpts, - TokenContract, TokenContractEventArgs, TokenEvents, TransactionOpts, @@ -21,6 +20,7 @@ import {constants} from '../utils/constants'; import {Web3Wrapper} from '../web3_wrapper'; import {ContractWrapper} from './contract_wrapper'; +import {TokenContract} from './generated/token'; import {TokenTransferProxyWrapper} from './token_transfer_proxy_wrapper'; const ALLOWANCE_TO_ZERO_GAS_AMOUNT = 47275; @@ -313,9 +313,12 @@ export class TokenWrapper extends ContractWrapper { if (!_.isUndefined(tokenContract)) { return tokenContract; } - const contractInstance = await this._instantiateContractIfExistsAsync<TokenContract>( + const web3ContractInstance = await this._instantiateContractIfExistsAsync( artifacts.TokenArtifact, tokenAddress, ); + const contractInstance = new TokenContract( + web3ContractInstance, this._web3Wrapper.getContractDefaults(), + ); tokenContract = contractInstance; this._tokenContractsByAddress[tokenAddress] = tokenContract; return tokenContract; |