/* * 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:CivilTCRContract"); export class CivilTCRContract extends BaseContract { // tslint:disable:member-ordering public static async singletonTrusted(ethApi: EthApi): Promise { if (!artifacts.CivilTCR.networks) { debug("Trying to get singleton from contract without any singleton data"); return undefined; } const networkId = (await currentNetwork(ethApi)).toString(); const networkData = artifacts.CivilTCR.networks[networkId]; if (!networkData) { debug("Failed to find network data for network ID " + networkId + ". Supported networks: " + Object.keys(artifacts.CivilTCR.networks)); return undefined; } return CivilTCRContract.atUntrusted(ethApi, networkData.address); } public static atUntrusted(ethApi: EthApi, address: EthAddress): CivilTCRContract { const contract = ethApi.getContractClass(artifacts.CivilTCR.abi, address); return new CivilTCRContract(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, token: string, plcr: string, param: string, govt: string, options: SendOptions): Promise { if (!options.gas) { options.gas = await CivilTCRContract.deployTrusted .estimateGasAsync( ethApi, token, plcr, param, govt, ); } if (!options.gasPrice) { options.gasPrice = (await ethApi.getGasPrice()).toString(); } const clazz = ethApi.getContractClass(artifacts.CivilTCR.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.CivilTCR.bytecode, arguments: [token, plcr, param, govt, ]}).send(options); return tx.once("transactionHash", resolve) }) }, async estimateGasAsync( ethApi: EthApi, token: string, plcr: string, param: string, govt: string, ): Promise { const clazz = ethApi.getContractClass(artifacts.CivilTCR.abi); const contractData = clazz.deploy({ data: artifacts.CivilTCR.bytecode, arguments: [token, plcr, param, govt, ] }).encodeABI(); return ethApi.estimateGas({data: contractData}); }, }; // tslint:disable:variable-name public name = { async callAsync( ): Promise { const self = this as CivilTCRContract; return self.instance.methods.name().call(); } } public civilVoting = { async callAsync( ): Promise { const self = this as CivilTCRContract; return self.instance.methods.civilVoting().call(); } } public government = { async callAsync( ): Promise { const self = this as CivilTCRContract; return self.instance.methods.government().call(); } } public isWhitelisted = { async callAsync( listingAddress: string, ): Promise { const self = this as CivilTCRContract; return self.instance.methods.isWhitelisted(listingAddress, ).call(); } } public deposit = { async sendTransactionAsync( listingAddress: string, _amount: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`deposit(listingAddress: string, _amount: BigNumber, )`); debug("deposit: txOptions:", txOptions); debug("deposit: Sending with:", listingAddress, _amount, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.deposit(listingAddress, _amount, ).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("deposit: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( listingAddress: string, _amount: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.deposit(listingAddress, _amount, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("deposit: Gas estimation:", estimate); return estimate; } catch (e) { debug("deposit: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( listingAddress: string, _amount: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.deposit.estimateGasAsync( listingAddress, _amount, options, ); } options.data = self.instance.methods.deposit(listingAddress, _amount, ).encodeABI(); return options; }, }; public claimRewards = { async sendTransactionAsync( _challengeIDs: BigNumber[], _salts: BigNumber[], txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`claimRewards(_challengeIDs: BigNumber[], _salts: BigNumber[], )`); debug("claimRewards: txOptions:", txOptions); debug("claimRewards: Sending with:", _challengeIDs, _salts, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.claimRewards(_challengeIDs, _salts, ).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("claimRewards: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( _challengeIDs: BigNumber[], _salts: BigNumber[], txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.claimRewards(_challengeIDs, _salts, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("claimRewards: Gas estimation:", estimate); return estimate; } catch (e) { debug("claimRewards: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( _challengeIDs: BigNumber[], _salts: BigNumber[], txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.claimRewards.estimateGasAsync( _challengeIDs, _salts, options, ); } options.data = self.instance.methods.claimRewards(_challengeIDs, _salts, ).encodeABI(); return options; }, }; public appWasMade = { async callAsync( listingAddress: string, ): Promise { const self = this as CivilTCRContract; return self.instance.methods.appWasMade(listingAddress, ).call(); } } public challengeRequestAppealExpiries = { async callAsync( index_0: BigNumber, ): Promise { const self = this as CivilTCRContract; return self.instance.methods.challengeRequestAppealExpiries(index_0, ).call(); } } public listings = { async callAsync( index_0: string, ): Promise< [BigNumber, boolean, string, BigNumber, BigNumber]> { const self = this as CivilTCRContract; return self.instance.methods.listings(index_0, ).call(); } } public challengeExists = { async callAsync( listingAddress: string, ): Promise { const self = this as CivilTCRContract; return self.instance.methods.challengeExists(listingAddress, ).call(); } } public challenges = { async callAsync( index_0: BigNumber, ): Promise< [BigNumber, string, boolean, BigNumber, BigNumber]> { const self = this as CivilTCRContract; return self.instance.methods.challenges(index_0, ).call(); } } public tokenClaims = { async callAsync( _challengeID: BigNumber, _voter: string, ): Promise { const self = this as CivilTCRContract; return self.instance.methods.tokenClaims(_challengeID, _voter, ).call(); } } public appeals = { async callAsync( index_0: BigNumber, ): Promise< [string, BigNumber, BigNumber, boolean, BigNumber, BigNumber, boolean]> { const self = this as CivilTCRContract; return self.instance.methods.appeals(index_0, ).call(); } } public exit = { async sendTransactionAsync( listingAddress: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`exit(listingAddress: string, )`); debug("exit: txOptions:", txOptions); debug("exit: Sending with:", listingAddress, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.exit(listingAddress, ).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("exit: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( listingAddress: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.exit(listingAddress, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("exit: Gas estimation:", estimate); return estimate; } catch (e) { debug("exit: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( listingAddress: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.exit.estimateGasAsync( listingAddress, options, ); } options.data = self.instance.methods.exit(listingAddress, ).encodeABI(); return options; }, }; public canBeWhitelisted = { async callAsync( listingAddress: string, ): Promise { const self = this as CivilTCRContract; return self.instance.methods.canBeWhitelisted(listingAddress, ).call(); } } public parameterizer = { async callAsync( ): Promise { const self = this as CivilTCRContract; return self.instance.methods.parameterizer().call(); } } public withdraw = { async sendTransactionAsync( listingAddress: string, _amount: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`withdraw(listingAddress: string, _amount: BigNumber, )`); debug("withdraw: txOptions:", txOptions); debug("withdraw: Sending with:", listingAddress, _amount, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.withdraw(listingAddress, _amount, ).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("withdraw: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( listingAddress: string, _amount: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.withdraw(listingAddress, _amount, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("withdraw: Gas estimation:", estimate); return estimate; } catch (e) { debug("withdraw: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( listingAddress: string, _amount: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.withdraw.estimateGasAsync( listingAddress, _amount, options, ); } options.data = self.instance.methods.withdraw(listingAddress, _amount, ).encodeABI(); return options; }, }; public updateStatuses = { async sendTransactionAsync( listingAddresses: string[], txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`updateStatuses(listingAddresses: string[], )`); debug("updateStatuses: txOptions:", txOptions); debug("updateStatuses: Sending with:", listingAddresses, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.updateStatuses(listingAddresses, ).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("updateStatuses: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( listingAddresses: string[], txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.updateStatuses(listingAddresses, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("updateStatuses: Gas estimation:", estimate); return estimate; } catch (e) { debug("updateStatuses: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( listingAddresses: string[], txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.updateStatuses.estimateGasAsync( listingAddresses, options, ); } options.data = self.instance.methods.updateStatuses(listingAddresses, ).encodeABI(); return options; }, }; public token = { async callAsync( ): Promise { const self = this as CivilTCRContract; return self.instance.methods.token().call(); } } public voting = { async callAsync( ): Promise { const self = this as CivilTCRContract; return self.instance.methods.voting().call(); } } public apply = { async sendTransactionAsync( listingAddress: string, amount: BigNumber, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`apply(listingAddress: string, amount: BigNumber, data: string, )`); debug("apply: txOptions:", txOptions); debug("apply: Sending with:", listingAddress, amount, data, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.apply(listingAddress, amount, data, ).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("apply: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( listingAddress: string, amount: BigNumber, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.apply(listingAddress, amount, data, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("apply: Gas estimation:", estimate); return estimate; } catch (e) { debug("apply: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( listingAddress: string, amount: BigNumber, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.apply.estimateGasAsync( listingAddress, amount, data, options, ); } options.data = self.instance.methods.apply(listingAddress, amount, data, ).encodeABI(); return options; }, }; public requestAppeal = { async sendTransactionAsync( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`requestAppeal(listingAddress: string, data: string, )`); debug("requestAppeal: txOptions:", txOptions); debug("requestAppeal: Sending with:", listingAddress, data, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.requestAppeal(listingAddress, data, ).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("requestAppeal: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.requestAppeal(listingAddress, data, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("requestAppeal: Gas estimation:", estimate); return estimate; } catch (e) { debug("requestAppeal: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.requestAppeal.estimateGasAsync( listingAddress, data, options, ); } options.data = self.instance.methods.requestAppeal(listingAddress, data, ).encodeABI(); return options; }, }; public grantAppeal = { async sendTransactionAsync( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`grantAppeal(listingAddress: string, data: string, )`); debug("grantAppeal: txOptions:", txOptions); debug("grantAppeal: Sending with:", listingAddress, data, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.grantAppeal(listingAddress, data, ).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("grantAppeal: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.grantAppeal(listingAddress, data, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("grantAppeal: Gas estimation:", estimate); return estimate; } catch (e) { debug("grantAppeal: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.grantAppeal.estimateGasAsync( listingAddress, data, options, ); } options.data = self.instance.methods.grantAppeal(listingAddress, data, ).encodeABI(); return options; }, }; public transferGovernment = { async sendTransactionAsync( newGovernment: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`transferGovernment(newGovernment: string, )`); debug("transferGovernment: txOptions:", txOptions); debug("transferGovernment: Sending with:", newGovernment, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.transferGovernment(newGovernment, ).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("transferGovernment: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( newGovernment: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.transferGovernment(newGovernment, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("transferGovernment: Gas estimation:", estimate); return estimate; } catch (e) { debug("transferGovernment: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( newGovernment: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.transferGovernment.estimateGasAsync( newGovernment, options, ); } options.data = self.instance.methods.transferGovernment(newGovernment, ).encodeABI(); return options; }, }; public updateStatus = { async sendTransactionAsync( listingAddress: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`updateStatus(listingAddress: string, )`); debug("updateStatus: txOptions:", txOptions); debug("updateStatus: Sending with:", listingAddress, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.updateStatus(listingAddress, ).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("updateStatus: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( listingAddress: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.updateStatus(listingAddress, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("updateStatus: Gas estimation:", estimate); return estimate; } catch (e) { debug("updateStatus: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( listingAddress: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.updateStatus.estimateGasAsync( listingAddress, options, ); } options.data = self.instance.methods.updateStatus(listingAddress, ).encodeABI(); return options; }, }; public challenge = { async sendTransactionAsync( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`challenge(listingAddress: string, data: string, )`); debug("challenge: txOptions:", txOptions); debug("challenge: Sending with:", listingAddress, data, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.challenge(listingAddress, data, ).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("challenge: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.challenge(listingAddress, data, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("challenge: Gas estimation:", estimate); return estimate; } catch (e) { debug("challenge: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.challenge.estimateGasAsync( listingAddress, data, options, ); } options.data = self.instance.methods.challenge(listingAddress, data, ).encodeABI(); return options; }, }; public challengeGrantedAppeal = { async sendTransactionAsync( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`challengeGrantedAppeal(listingAddress: string, data: string, )`); debug("challengeGrantedAppeal: txOptions:", txOptions); debug("challengeGrantedAppeal: Sending with:", listingAddress, data, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.challengeGrantedAppeal(listingAddress, data, ).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("challengeGrantedAppeal: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.challengeGrantedAppeal(listingAddress, data, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("challengeGrantedAppeal: Gas estimation:", estimate); return estimate; } catch (e) { debug("challengeGrantedAppeal: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( listingAddress: string, data: string, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.challengeGrantedAppeal.estimateGasAsync( listingAddress, data, options, ); } options.data = self.instance.methods.challengeGrantedAppeal(listingAddress, data, ).encodeABI(); return options; }, }; public claimReward = { async sendTransactionAsync( _challengeID: BigNumber, _salt: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`claimReward(_challengeID: BigNumber, _salt: BigNumber, )`); debug("claimReward: txOptions:", txOptions); debug("claimReward: Sending with:", _challengeID, _salt, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.claimReward(_challengeID, _salt, ).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("claimReward: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( _challengeID: BigNumber, _salt: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const estimateGas = self.instance.methods.claimReward(_challengeID, _salt, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("claimReward: Gas estimation:", estimate); return estimate; } catch (e) { debug("claimReward: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( _challengeID: BigNumber, _salt: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilTCRContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.claimReward.estimateGasAsync( _challengeID, _salt, options, ); } options.data = self.instance.methods.claimReward(_challengeID, _salt, ).encodeABI(); return options; }, }; public determineReward = { async callAsync( challengeID: BigNumber, ): Promise { const self = this as CivilTCRContract; return self.instance.methods.determineReward(challengeID, ).call(); } } public voterReward = { async callAsync( voter: string, challengeID: BigNumber, salt: BigNumber, ): Promise { const self = this as CivilTCRContract; return self.instance.methods.voterReward(voter, challengeID, salt, ).call(); } } public challengeCanBeResolved = { async callAsync( listingAddress: string, ): Promise { const self = this as CivilTCRContract; return self.instance.methods.challengeCanBeResolved(listingAddress, ).call(); } } public appealCanBeResolved = { async callAsync( listingAddress: string, ): Promise { const self = this as CivilTCRContract; return self.instance.methods.appealCanBeResolved(listingAddress, ).call(); } } public appealChallengeCanBeResolved = { async callAsync( listingAddress: string, ): Promise { const self = this as CivilTCRContract; return self.instance.methods.appealChallengeCanBeResolved(listingAddress, ).call(); } } public _AppealRequestedStream = streamifyEvent (this.instance, "_AppealRequested"); public _AppealGrantedStream = streamifyEvent (this.instance, "_AppealGranted"); public _FailedChallengeOverturnedStream = streamifyEvent (this.instance, "_FailedChallengeOverturned"); public _SuccessfulChallengeOverturnedStream = streamifyEvent (this.instance, "_SuccessfulChallengeOverturned"); public _GrantedAppealChallengedStream = streamifyEvent (this.instance, "_GrantedAppealChallenged"); public _GrantedAppealOverturnedStream = streamifyEvent (this.instance, "_GrantedAppealOverturned"); public _GrantedAppealConfirmedStream = streamifyEvent (this.instance, "_GrantedAppealConfirmed"); public _GovernmentTransferedStream = streamifyEvent (this.instance, "_GovernmentTransfered"); public _ApplicationStream = streamifyEvent (this.instance, "_Application"); public _ChallengeStream = streamifyEvent (this.instance, "_Challenge"); public _DepositStream = streamifyEvent (this.instance, "_Deposit"); public _WithdrawalStream = streamifyEvent (this.instance, "_Withdrawal"); public _ApplicationWhitelistedStream = streamifyEvent (this.instance, "_ApplicationWhitelisted"); public _ApplicationRemovedStream = streamifyEvent (this.instance, "_ApplicationRemoved"); public _ListingRemovedStream = streamifyEvent (this.instance, "_ListingRemoved"); public _ListingWithdrawnStream = streamifyEvent (this.instance, "_ListingWithdrawn"); public _TouchAndRemovedStream = streamifyEvent (this.instance, "_TouchAndRemoved"); public _ChallengeFailedStream = streamifyEvent (this.instance, "_ChallengeFailed"); public _ChallengeSucceededStream = streamifyEvent (this.instance, "_ChallengeSucceeded"); public _RewardClaimedStream = streamifyEvent (this.instance, "_RewardClaimed"); // 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 CivilTCR { export enum Events { _AppealRequested = "_AppealRequested", _AppealGranted = "_AppealGranted", _FailedChallengeOverturned = "_FailedChallengeOverturned", _SuccessfulChallengeOverturned = "_SuccessfulChallengeOverturned", _GrantedAppealChallenged = "_GrantedAppealChallenged", _GrantedAppealOverturned = "_GrantedAppealOverturned", _GrantedAppealConfirmed = "_GrantedAppealConfirmed", _GovernmentTransfered = "_GovernmentTransfered", _Application = "_Application", _Challenge = "_Challenge", _Deposit = "_Deposit", _Withdrawal = "_Withdrawal", _ApplicationWhitelisted = "_ApplicationWhitelisted", _ApplicationRemoved = "_ApplicationRemoved", _ListingRemoved = "_ListingRemoved", _ListingWithdrawn = "_ListingWithdrawn", _TouchAndRemoved = "_TouchAndRemoved", _ChallengeFailed = "_ChallengeFailed", _ChallengeSucceeded = "_ChallengeSucceeded", _RewardClaimed = "_RewardClaimed", } // tslint:disable:class-name export namespace Args { export interface _AppealRequested { listingAddress: string; challengeID: BigNumber; appealFeePaid: BigNumber; requester: string; data: string; } export interface _AppealGranted { listingAddress: string; challengeID: BigNumber; data: string; } export interface _FailedChallengeOverturned { listingAddress: string; challengeID: BigNumber; rewardPool: BigNumber; totalTokens: BigNumber; } export interface _SuccessfulChallengeOverturned { listingAddress: string; challengeID: BigNumber; rewardPool: BigNumber; totalTokens: BigNumber; } export interface _GrantedAppealChallenged { listingAddress: string; challengeID: BigNumber; appealChallengeID: BigNumber; data: string; } export interface _GrantedAppealOverturned { listingAddress: string; challengeID: BigNumber; appealChallengeID: BigNumber; rewardPool: BigNumber; totalTokens: BigNumber; } export interface _GrantedAppealConfirmed { listingAddress: string; challengeID: BigNumber; appealChallengeID: BigNumber; rewardPool: BigNumber; totalTokens: BigNumber; } export interface _GovernmentTransfered { newGovernment: string; } export interface _Application { listingAddress: string; deposit: BigNumber; appEndDate: BigNumber; data: string; applicant: string; } export interface _Challenge { listingAddress: string; challengeID: BigNumber; data: string; commitEndDate: BigNumber; revealEndDate: BigNumber; challenger: string; } export interface _Deposit { listingAddress: string; added: BigNumber; newTotal: BigNumber; owner: string; } export interface _Withdrawal { listingAddress: string; withdrew: BigNumber; newTotal: BigNumber; owner: string; } export interface _ApplicationWhitelisted { listingAddress: string; } export interface _ApplicationRemoved { listingAddress: string; } export interface _ListingRemoved { listingAddress: string; } export interface _ListingWithdrawn { listingAddress: string; } export interface _TouchAndRemoved { listingAddress: string; } export interface _ChallengeFailed { listingAddress: string; challengeID: BigNumber; rewardPool: BigNumber; totalTokens: BigNumber; } export interface _ChallengeSucceeded { listingAddress: string; challengeID: BigNumber; rewardPool: BigNumber; totalTokens: BigNumber; } export interface _RewardClaimed { challengeID: BigNumber; reward: BigNumber; voter: string; } } // tslint:enable:class-name export namespace Logs { export type _AppealRequested = DecodedLogEntry; export type _AppealGranted = DecodedLogEntry; export type _FailedChallengeOverturned = DecodedLogEntry; export type _SuccessfulChallengeOverturned = DecodedLogEntry; export type _GrantedAppealChallenged = DecodedLogEntry; export type _GrantedAppealOverturned = DecodedLogEntry; export type _GrantedAppealConfirmed = DecodedLogEntry; export type _GovernmentTransfered = DecodedLogEntry; export type _Application = DecodedLogEntry; export type _Challenge = DecodedLogEntry; export type _Deposit = DecodedLogEntry; export type _Withdrawal = DecodedLogEntry; export type _ApplicationWhitelisted = DecodedLogEntry; export type _ApplicationRemoved = DecodedLogEntry; export type _ListingRemoved = DecodedLogEntry; export type _ListingWithdrawn = DecodedLogEntry; export type _TouchAndRemoved = DecodedLogEntry; export type _ChallengeFailed = DecodedLogEntry; export type _ChallengeSucceeded = DecodedLogEntry; export type _RewardClaimed = DecodedLogEntry; export type All = Logs._AppealRequested | Logs._AppealGranted | Logs._FailedChallengeOverturned | Logs._SuccessfulChallengeOverturned | Logs._GrantedAppealChallenged | Logs._GrantedAppealOverturned | Logs._GrantedAppealConfirmed | Logs._GovernmentTransfered | Logs._Application | Logs._Challenge | Logs._Deposit | Logs._Withdrawal | Logs._ApplicationWhitelisted | Logs._ApplicationRemoved | Logs._ListingRemoved | Logs._ListingWithdrawn | Logs._TouchAndRemoved | Logs._ChallengeFailed | Logs._ChallengeSucceeded | Logs._RewardClaimed; } export namespace LogEvents { export type _AppealRequested = DecodedLogEntryEvent; export type _AppealGranted = DecodedLogEntryEvent; export type _FailedChallengeOverturned = DecodedLogEntryEvent; export type _SuccessfulChallengeOverturned = DecodedLogEntryEvent; export type _GrantedAppealChallenged = DecodedLogEntryEvent; export type _GrantedAppealOverturned = DecodedLogEntryEvent; export type _GrantedAppealConfirmed = DecodedLogEntryEvent; export type _GovernmentTransfered = DecodedLogEntryEvent; export type _Application = DecodedLogEntryEvent; export type _Challenge = DecodedLogEntryEvent; export type _Deposit = DecodedLogEntryEvent; export type _Withdrawal = DecodedLogEntryEvent; export type _ApplicationWhitelisted = DecodedLogEntryEvent; export type _ApplicationRemoved = DecodedLogEntryEvent; export type _ListingRemoved = DecodedLogEntryEvent; export type _ListingWithdrawn = DecodedLogEntryEvent; export type _TouchAndRemoved = DecodedLogEntryEvent; export type _ChallengeFailed = DecodedLogEntryEvent; export type _ChallengeSucceeded = DecodedLogEntryEvent; export type _RewardClaimed = DecodedLogEntryEvent; export type All = LogEvents._AppealRequested | LogEvents._AppealGranted | LogEvents._FailedChallengeOverturned | LogEvents._SuccessfulChallengeOverturned | LogEvents._GrantedAppealChallenged | LogEvents._GrantedAppealOverturned | LogEvents._GrantedAppealConfirmed | LogEvents._GovernmentTransfered | LogEvents._Application | LogEvents._Challenge | LogEvents._Deposit | LogEvents._Withdrawal | LogEvents._ApplicationWhitelisted | LogEvents._ApplicationRemoved | LogEvents._ListingRemoved | LogEvents._ListingWithdrawn | LogEvents._TouchAndRemoved | LogEvents._ChallengeFailed | LogEvents._ChallengeSucceeded | LogEvents._RewardClaimed; } export type Receipt = DecodedTransactionReceipt; export type EventReceipt = DecodedTransactionReceipt; } // tslint:enable:no-namespace