/* * 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:CivilParameterizerContract"); export class CivilParameterizerContract extends BaseContract { // tslint:disable:member-ordering public static async singletonTrusted(ethApi: EthApi): Promise { if (!artifacts.CivilParameterizer.networks) { debug("Trying to get singleton from contract without any singleton data"); return undefined; } const networkId = (await currentNetwork(ethApi)).toString(); const networkData = artifacts.CivilParameterizer.networks[networkId]; if (!networkData) { debug("Failed to find network data for network ID " + networkId + ". Supported networks: " + Object.keys(artifacts.CivilParameterizer.networks)); return undefined; } return CivilParameterizerContract.atUntrusted(ethApi, networkData.address); } public static atUntrusted(ethApi: EthApi, address: EthAddress): CivilParameterizerContract { const contract = ethApi.getContractClass(artifacts.CivilParameterizer.abi, address); return new CivilParameterizerContract(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, tokenAddr: string, plcrAddr: string, parameters: BigNumber[], options: SendOptions): Promise { if (!options.gas) { options.gas = await CivilParameterizerContract.deployTrusted .estimateGasAsync( ethApi, tokenAddr, plcrAddr, parameters, ); } if (!options.gasPrice) { options.gasPrice = (await ethApi.getGasPrice()).toString(); } const clazz = ethApi.getContractClass(artifacts.CivilParameterizer.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.CivilParameterizer.bytecode, arguments: [tokenAddr, plcrAddr, parameters, ]}).send(options); return tx.once("transactionHash", resolve) }) }, async estimateGasAsync( ethApi: EthApi, tokenAddr: string, plcrAddr: string, parameters: BigNumber[], ): Promise { const clazz = ethApi.getContractClass(artifacts.CivilParameterizer.abi); const contractData = clazz.deploy({ data: artifacts.CivilParameterizer.bytecode, arguments: [tokenAddr, plcrAddr, parameters, ] }).encodeABI(); return ethApi.estimateGas({data: contractData}); }, }; // tslint:disable:variable-name public PROCESSBY = { async callAsync( ): Promise { const self = this as CivilParameterizerContract; return self.instance.methods.PROCESSBY().call(); } } public processProposal = { async sendTransactionAsync( _propID: string, txData?: TransactionConfig, ): Promise { const self = this as CivilParameterizerContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`processProposal(_propID: string, )`); debug("processProposal: txOptions:", txOptions); debug("processProposal: Sending with:", _propID, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.processProposal(_propID, ).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("processProposal: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( _propID: string, txData?: TransactionConfig, ): Promise { const self = this as CivilParameterizerContract; const estimateGas = self.instance.methods.processProposal(_propID, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("processProposal: Gas estimation:", estimate); return estimate; } catch (e) { debug("processProposal: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( _propID: string, txData?: TransactionConfig, ): Promise { const self = this as CivilParameterizerContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.processProposal.estimateGasAsync( _propID, options, ); } options.data = self.instance.methods.processProposal(_propID, ).encodeABI(); return options; }, }; public proposals = { async callAsync( index_0: string, ): Promise< [BigNumber, BigNumber, BigNumber, string, string, BigNumber, BigNumber]> { const self = this as CivilParameterizerContract; return self.instance.methods.proposals(index_0, ).call(); } } public propExists = { async callAsync( _propID: string, ): Promise { const self = this as CivilParameterizerContract; return self.instance.methods.propExists(_propID, ).call(); } } public challengeWinnerReward = { async callAsync( _challengeID: BigNumber, ): Promise { const self = this as CivilParameterizerContract; return self.instance.methods.challengeWinnerReward(_challengeID, ).call(); } } public claimRewards = { async sendTransactionAsync( _challengeIDs: BigNumber[], _salts: BigNumber[], txData?: TransactionConfig, ): Promise { const self = this as CivilParameterizerContract; 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 CivilParameterizerContract; 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 CivilParameterizerContract; 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 get = { async callAsync( _name: string, ): Promise { const self = this as CivilParameterizerContract; return self.instance.methods.get(_name, ).call(); } } public challengeCanBeResolved = { async callAsync( _propID: string, ): Promise { const self = this as CivilParameterizerContract; return self.instance.methods.challengeCanBeResolved(_propID, ).call(); } } public challengeReparameterization = { async sendTransactionAsync( _propID: string, txData?: TransactionConfig, ): Promise { const self = this as CivilParameterizerContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`challengeReparameterization(_propID: string, )`); debug("challengeReparameterization: txOptions:", txOptions); debug("challengeReparameterization: Sending with:", _propID, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.challengeReparameterization(_propID, ).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("challengeReparameterization: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( _propID: string, txData?: TransactionConfig, ): Promise { const self = this as CivilParameterizerContract; const estimateGas = self.instance.methods.challengeReparameterization(_propID, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("challengeReparameterization: Gas estimation:", estimate); return estimate; } catch (e) { debug("challengeReparameterization: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( _propID: string, txData?: TransactionConfig, ): Promise { const self = this as CivilParameterizerContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.challengeReparameterization.estimateGasAsync( _propID, options, ); } options.data = self.instance.methods.challengeReparameterization(_propID, ).encodeABI(); return options; }, }; public claimReward = { async sendTransactionAsync( _challengeID: BigNumber, _salt: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilParameterizerContract; 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 CivilParameterizerContract; 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 CivilParameterizerContract; 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 challenges = { async callAsync( index_0: BigNumber, ): Promise< [BigNumber, string, boolean, BigNumber, BigNumber]> { const self = this as CivilParameterizerContract; return self.instance.methods.challenges(index_0, ).call(); } } public tokenClaims = { async callAsync( _challengeID: BigNumber, _voter: string, ): Promise { const self = this as CivilParameterizerContract; return self.instance.methods.tokenClaims(_challengeID, _voter, ).call(); } } public voterReward = { async callAsync( _voter: string, _challengeID: BigNumber, _salt: BigNumber, ): Promise { const self = this as CivilParameterizerContract; return self.instance.methods.voterReward(_voter, _challengeID, _salt, ).call(); } } public proposeReparameterization = { async sendTransactionAsync( _name: string, _value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilParameterizerContract; const txOptions: TransactionConfig = { ...self.configuration.txDefaults, ...txData }; debug(`proposeReparameterization(_name: string, _value: BigNumber, )`); debug("proposeReparameterization: txOptions:", txOptions); debug("proposeReparameterization: Sending with:", _name, _value, ); txOptions.to = self.instance.options.address; txOptions.data = self.instance.methods.proposeReparameterization(_name, _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("proposeReparameterization: new gas price: ", txOptions.gasPrice); } return self.ethApi.sendTransaction(txOptions) }, async estimateGasAsync( _name: string, _value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilParameterizerContract; const estimateGas = self.instance.methods.proposeReparameterization(_name, _value, ).estimateGas try { const estimate = Math.floor(await estimateGas(txData) * self.configuration.estimationMultiplier); debug("proposeReparameterization: Gas estimation:", estimate); return estimate; } catch (e) { debug("proposeReparameterization: Gas estimation failed, only sensible error is EVM error", e); throw new Error(CivilErrors.EvmException); } }, async getRaw( _name: string, _value: BigNumber, txData?: TransactionConfig, ): Promise { const self = this as CivilParameterizerContract; const options: TransactionConfig = {... txData}; if (!isDefined(options.gas)) { options.gas = await self.proposeReparameterization.estimateGasAsync( _name, _value, options, ); } options.data = self.instance.methods.proposeReparameterization(_name, _value, ).encodeABI(); return options; }, }; public canBeSet = { async callAsync( _propID: string, ): Promise { const self = this as CivilParameterizerContract; return self.instance.methods.canBeSet(_propID, ).call(); } } public params = { async callAsync( index_0: string, ): Promise { const self = this as CivilParameterizerContract; return self.instance.methods.params(index_0, ).call(); } } public token = { async callAsync( ): Promise { const self = this as CivilParameterizerContract; return self.instance.methods.token().call(); } } public voting = { async callAsync( ): Promise { const self = this as CivilParameterizerContract; return self.instance.methods.voting().call(); } } public _ReparameterizationProposalStream = streamifyEvent (this.instance, "_ReparameterizationProposal"); public _NewChallengeStream = streamifyEvent (this.instance, "_NewChallenge"); public _ProposalAcceptedStream = streamifyEvent (this.instance, "_ProposalAccepted"); public _ProposalExpiredStream = streamifyEvent (this.instance, "_ProposalExpired"); public _ChallengeSucceededStream = streamifyEvent (this.instance, "_ChallengeSucceeded"); public _ChallengeFailedStream = streamifyEvent (this.instance, "_ChallengeFailed"); 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 CivilParameterizer { export enum Events { _ReparameterizationProposal = "_ReparameterizationProposal", _NewChallenge = "_NewChallenge", _ProposalAccepted = "_ProposalAccepted", _ProposalExpired = "_ProposalExpired", _ChallengeSucceeded = "_ChallengeSucceeded", _ChallengeFailed = "_ChallengeFailed", _RewardClaimed = "_RewardClaimed", } // tslint:disable:class-name export namespace Args { export interface _ReparameterizationProposal { name: string; value: BigNumber; propID: string; deposit: BigNumber; appEndDate: BigNumber; proposer: string; } export interface _NewChallenge { propID: string; challengeID: BigNumber; commitEndDate: BigNumber; revealEndDate: BigNumber; challenger: string; } export interface _ProposalAccepted { propID: string; name: string; value: BigNumber; } export interface _ProposalExpired { propID: string; } export interface _ChallengeSucceeded { propID: string; challengeID: BigNumber; rewardPool: BigNumber; totalTokens: BigNumber; } export interface _ChallengeFailed { propID: 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 _ReparameterizationProposal = DecodedLogEntry; export type _NewChallenge = DecodedLogEntry; export type _ProposalAccepted = DecodedLogEntry; export type _ProposalExpired = DecodedLogEntry; export type _ChallengeSucceeded = DecodedLogEntry; export type _ChallengeFailed = DecodedLogEntry; export type _RewardClaimed = DecodedLogEntry; export type All = Logs._ReparameterizationProposal | Logs._NewChallenge | Logs._ProposalAccepted | Logs._ProposalExpired | Logs._ChallengeSucceeded | Logs._ChallengeFailed | Logs._RewardClaimed; } export namespace LogEvents { export type _ReparameterizationProposal = DecodedLogEntryEvent; export type _NewChallenge = DecodedLogEntryEvent; export type _ProposalAccepted = DecodedLogEntryEvent; export type _ProposalExpired = DecodedLogEntryEvent; export type _ChallengeSucceeded = DecodedLogEntryEvent; export type _ChallengeFailed = DecodedLogEntryEvent; export type _RewardClaimed = DecodedLogEntryEvent; export type All = LogEvents._ReparameterizationProposal | LogEvents._NewChallenge | LogEvents._ProposalAccepted | LogEvents._ProposalExpired | LogEvents._ChallengeSucceeded | LogEvents._ChallengeFailed | LogEvents._RewardClaimed; } export type Receipt = DecodedTransactionReceipt; export type EventReceipt = DecodedTransactionReceipt; } // tslint:enable:no-namespace