/* * This file is auto-generated using abi-gen. Any changes will be reverted */ // Needed for the promisifed events, some contracts don't have events // tslint:disable:no-unused-variable import { DecodedLogEntryEvent, DecodedLogEntry, DecodedTransactionReceipt } from "@joincivil/typescript-types"; // tslint:enable:no-unused-variable import "rxjs/add/operator/distinctUntilChanged"; import {Contract} from "web3-eth-contract"; import {TransactionConfig, TransactionConfig as SendOptions} from "web3-core"; import { bindNestedAll, isDefined, CivilErrors } from "@joincivil/utils"; import * as Debug from "debug"; import { EthAddress, TxHash } from "@joincivil/typescript-types"; import { streamifyEvent } from "../../../contracts/utils/contracts"; import { EthApi, currentNetwork } from "@joincivil/ethapi"; import { BaseContract } from "../../basecontract"; import { artifacts } from "../artifacts"; // hack(dankins): abi-gen things these are bignumber.js, but they are actually returned as strings // https://github.com/0xProject/0x-monorepo/blob/development/packages/abi-gen/src/utils.ts#L64 type BigNumber = string; const debug = Debug("civil:contracts:CVLTokenContract"); export class CVLTokenContract extends BaseContract { // tslint:disable:member-ordering public static async singletonTrusted(ethApi: EthApi): Promise { if (!artifacts.CVLToken.networks) { debug("Trying to get singleton from contract without any singleton data"); return undefined; } const networkId = (await currentNetwork(ethApi)).toString(); const networkData = artifacts.CVLToken.networks[networkId]; if (!networkData) { debug("Failed to find network data for network ID " + networkId + ". Supported networks: " + Object.keys(artifacts.CVLToken.networks)); return undefined; } return CVLTokenContract.atUntrusted(ethApi, networkData.address); } public static atUntrusted(ethApi: EthApi, address: EthAddress): CVLTokenContract { const contract = ethApi.getContractClass(artifacts.CVLToken.abi, address); return new CVLTokenContract(contract, ethApi); } // TODO(ritave): This code won't work with smart-contracts with library links // see [ch429] in Clubhouse public static deployTrusted = { async sendTransactionAsync( ethApi: EthApi, _initialAmount: BigNumber, _tokenName: string, _decimalUnits: number|BigNumber, _tokenSymbol: string, _controller: string, options: SendOptions): Promise { if (!options.gas) { options.gas = await CVLTokenContract.deployTrusted .estimateGasAsync( ethApi, _initialAmount, _tokenName, _decimalUnits, _tokenSymbol, _controller, ); } if (!options.gasPrice) { options.gasPrice = (await ethApi.getGasPrice()).toString(); } const clazz = ethApi.getContractClass(artifacts.CVLToken.abi); return new Promise( (resolve, reject) => { /* There's a bug in Metamask, this callback should be called twice, first when the transaction * gets into mempool, and second when it's mined. But it's called only once, so we have to resolve * the contract on our own */ const tx = clazz.deploy({data: artifacts.CVLToken.bytecode, arguments: [_initialAmount, _tokenName, _decimalUnits, _tokenSymbol, _controller, ]}).send(options); return tx.once("transactionHash", resolve) }) }, async estimateGasAsync( ethApi: EthApi, _initialAmount: BigNumber, _tokenName: string, _decimalUnits: number|BigNumber, _tokenSymbol: string, _controller: string, ): Promise { const clazz = ethApi.getContractClass(artifacts.CVLToken.abi); const contractData = clazz.deploy({ data: artifacts.CVLToken.bytecode, arguments: [_initialAmount, _tokenName, _decimalUnits, _tokenSymbol, _controller, ] }).encodeABI(); return ethApi.estimateGas({data: contractData}); }, }; // tslint:disable:variable-name public name = { async callAsync( ): Promise { const self = this as CVLTokenContract; return self.instance.methods.name().call(); } } public approve = { async sendTransactionAsync( spender: string, value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`approve(spender: string, value: BigNumber, )`); debug("approve: txOptions:", txOptions); debug("approve: Sending with:", spender, value, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.approve(spender, value, ).encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("approve: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( spender: string, value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const estimateGas = self.instance.methods.approve(spender, value, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("approve: Gas estimation:", estimate); return estimate; } catch (e) { debug("approve: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( spender: string, value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.approve.estimateGasAsync( spender, value, options, ); } options.data = self.instance.methods.approve(spender, value, ).encodeABI(); return options; }, }; public totalSupply = { async callAsync( ): Promise { const self = this as CVLTokenContract; return self.instance.methods.totalSupply().call(); } } public decimals = { async callAsync( ): Promise { const self = this as CVLTokenContract; return self.instance.methods.decimals().call(); } } public increaseAllowance = { async sendTransactionAsync( spender: string, addedValue: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`increaseAllowance(spender: string, addedValue: BigNumber, )`); debug("increaseAllowance: txOptions:", txOptions); debug("increaseAllowance: Sending with:", spender, addedValue, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.increaseAllowance(spender, addedValue, ).encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("increaseAllowance: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( spender: string, addedValue: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const estimateGas = self.instance.methods.increaseAllowance(spender, addedValue, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("increaseAllowance: Gas estimation:", estimate); return estimate; } catch (e) { debug("increaseAllowance: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( spender: string, addedValue: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.increaseAllowance.estimateGasAsync( spender, addedValue, options, ); } options.data = self.instance.methods.increaseAllowance(spender, addedValue, ).encodeABI(); return options; }, }; public balanceOf = { async callAsync( owner: string, ): Promise { const self = this as CVLTokenContract; return self.instance.methods.balanceOf(owner, ).call(); } } public renounceOwnership = { async sendTransactionAsync( txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`renounceOwnership()`); debug("renounceOwnership: txOptions:", txOptions); debug("renounceOwnership: Sending with:", ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.renounceOwnership().encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("renounceOwnership: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const estimateGas = self.instance.methods.renounceOwnership().estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("renounceOwnership: Gas estimation:", estimate); return estimate; } catch (e) { debug("renounceOwnership: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.renounceOwnership.estimateGasAsync( options, ); } options.data = self.instance.methods.renounceOwnership().encodeABI(); return options; }, }; public owner = { async callAsync( ): Promise { const self = this as CVLTokenContract; return self.instance.methods.owner().call(); } } public symbol = { async callAsync( ): Promise { const self = this as CVLTokenContract; return self.instance.methods.symbol().call(); } } public decreaseAllowance = { async sendTransactionAsync( spender: string, subtractedValue: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`decreaseAllowance(spender: string, subtractedValue: BigNumber, )`); debug("decreaseAllowance: txOptions:", txOptions); debug("decreaseAllowance: Sending with:", spender, subtractedValue, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.decreaseAllowance(spender, subtractedValue, ).encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("decreaseAllowance: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( spender: string, subtractedValue: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const estimateGas = self.instance.methods.decreaseAllowance(spender, subtractedValue, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("decreaseAllowance: Gas estimation:", estimate); return estimate; } catch (e) { debug("decreaseAllowance: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( spender: string, subtractedValue: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.decreaseAllowance.estimateGasAsync( spender, subtractedValue, options, ); } options.data = self.instance.methods.decreaseAllowance(spender, subtractedValue, ).encodeABI(); return options; }, }; public allowance = { async callAsync( owner: string, spender: string, ): Promise { const self = this as CVLTokenContract; return self.instance.methods.allowance(owner, spender, ).call(); } } public transferOwnership = { async sendTransactionAsync( _newOwner: string, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`transferOwnership(_newOwner: string, )`); debug("transferOwnership: txOptions:", txOptions); debug("transferOwnership: Sending with:", _newOwner, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.transferOwnership(_newOwner, ).encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("transferOwnership: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( _newOwner: string, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const estimateGas = self.instance.methods.transferOwnership(_newOwner, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("transferOwnership: Gas estimation:", estimate); return estimate; } catch (e) { debug("transferOwnership: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( _newOwner: string, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.transferOwnership.estimateGasAsync( _newOwner, options, ); } options.data = self.instance.methods.transferOwnership(_newOwner, ).encodeABI(); return options; }, }; public controller = { async callAsync( ): Promise { const self = this as CVLTokenContract; return self.instance.methods.controller().call(); } } public changeController = { async sendTransactionAsync( _controller: string, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`changeController(_controller: string, )`); debug("changeController: txOptions:", txOptions); debug("changeController: Sending with:", _controller, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.changeController(_controller, ).encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("changeController: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( _controller: string, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const estimateGas = self.instance.methods.changeController(_controller, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("changeController: Gas estimation:", estimate); return estimate; } catch (e) { debug("changeController: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( _controller: string, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.changeController.estimateGasAsync( _controller, options, ); } options.data = self.instance.methods.changeController(_controller, ).encodeABI(); return options; }, }; public transfer = { async sendTransactionAsync( to: string, value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`transfer(to: string, value: BigNumber, )`); debug("transfer: txOptions:", txOptions); debug("transfer: Sending with:", to, value, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.transfer(to, value, ).encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("transfer: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( to: string, value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const estimateGas = self.instance.methods.transfer(to, value, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("transfer: Gas estimation:", estimate); return estimate; } catch (e) { debug("transfer: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( to: string, value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.transfer.estimateGasAsync( to, value, options, ); } options.data = self.instance.methods.transfer(to, value, ).encodeABI(); return options; }, }; public transferFrom = { async sendTransactionAsync( from: string, to: string, value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`transferFrom(from: string, to: string, value: BigNumber, )`); debug("transferFrom: txOptions:", txOptions); debug("transferFrom: Sending with:", from, to, value, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.transferFrom(from, to, value, ).encodeABI(); if (!isDefined(txOptions.gas)) { txOptions.gas = await self.ethApi.estimateGas(txOptions); } if (!isDefined(txOptions.gasPrice)) { const gasPricePromise = self.ethApi.getGasPriceString() txOptions.gasPrice = (await gasPricePromise).toString(); debug("transferFrom: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( from: string, to: string, value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const estimateGas = self.instance.methods.transferFrom(from, to, value, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("transferFrom: Gas estimation:", estimate); return estimate; } catch (e) { debug("transferFrom: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( from: string, to: string, value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CVLTokenContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.transferFrom.estimateGasAsync( from, to, value, options, ); } options.data = self.instance.methods.transferFrom(from, to, value, ).encodeABI(); return options; }, }; public detectTransferRestriction = { async callAsync( from: string, to: string, value: BigNumber, ): Promise { const self = this as CVLTokenContract; return self.instance.methods.detectTransferRestriction(from, to, value, ).call(); } } public messageForTransferRestriction = { async callAsync( restrictionCode: number|BigNumber, ): Promise { const self = this as CVLTokenContract; return self.instance.methods.messageForTransferRestriction(restrictionCode, ).call(); } } public OwnershipRenouncedStream = streamifyEvent (this.instance, "OwnershipRenounced"); public OwnershipTransferredStream = streamifyEvent (this.instance, "OwnershipTransferred"); public TransferStream = streamifyEvent (this.instance, "Transfer"); public ApprovalStream = streamifyEvent (this.instance, "Approval"); // tslint:enable:variable-name private constructor(instance: Contract, ethApi: EthApi) { super(instance, ethApi); // Call methods access this instance while being in a sub-object, we're rebinding what // "this" means for everything in this class, this also requires "noImplicitThis" to be false bindNestedAll(this, ["constructor", "instance", "defaults", "ethApi"]); } // tslint:enable:member-ordering } // tslint:disable:no-namespace export namespace CVLToken { export enum Events { OwnershipRenounced = "OwnershipRenounced", OwnershipTransferred = "OwnershipTransferred", Transfer = "Transfer", Approval = "Approval", } // tslint:disable:class-name export namespace Args { export interface OwnershipRenounced { previousOwner: string; } export interface OwnershipTransferred { previousOwner: string; newOwner: string; } export interface Transfer { from: string; to: string; value: BigNumber; } export interface Approval { owner: string; spender: string; value: BigNumber; } } // tslint:enable:class-name export namespace Logs { export type OwnershipRenounced = DecodedLogEntry; export type OwnershipTransferred = DecodedLogEntry; export type Transfer = DecodedLogEntry; export type Approval = DecodedLogEntry; export type All = Logs.OwnershipRenounced | Logs.OwnershipTransferred | Logs.Transfer | Logs.Approval; } export namespace LogEvents { export type OwnershipRenounced = DecodedLogEntryEvent; export type OwnershipTransferred = DecodedLogEntryEvent; export type Transfer = DecodedLogEntryEvent; export type Approval = DecodedLogEntryEvent; export type All = LogEvents.OwnershipRenounced | LogEvents.OwnershipTransferred | LogEvents.Transfer | LogEvents.Approval; } export type Receipt = DecodedTransactionReceipt; export type EventReceipt = DecodedTransactionReceipt; } // tslint:enable:no-namespace