UNPKG

@celo/contractkit

Version:

Celo's ContractKit to interact with Celo network

390 lines (389 loc) 15.6 kB
/// <reference types="node" /> import { Governance } from '@celo/abis/web3/Governance'; import { Address, CeloTxPending } from '@celo/connect'; import BigNumber from 'bignumber.js'; import { BaseWrapperForGoverning } from './BaseWrapperForGoverning'; export declare enum ProposalStage { None = "None", Queued = "Queued", Approval = "Approval", Referendum = "Referendum", Execution = "Execution", Expiration = "Expiration" } type StageDurations<V> = { [Stage in ProposalStage]: V; }; type DequeuedStageDurations = Pick<StageDurations<BigNumber>, ProposalStage.Referendum | ProposalStage.Execution>; export interface ParticipationParameters { baseline: BigNumber; baselineFloor: BigNumber; baselineUpdateFactor: BigNumber; baselineQuorumFactor: BigNumber; } export interface GovernanceConfig { concurrentProposals: BigNumber; dequeueFrequency: BigNumber; minDeposit: BigNumber; queueExpiry: BigNumber; stageDurations: DequeuedStageDurations; participationParameters: ParticipationParameters; } export interface ProposalMetadata { proposer: Address; deposit: BigNumber; timestamp: BigNumber; transactionCount: number; descriptionURL: string; } export type ProposalParams = Parameters<Governance['methods']['propose']>; export type ProposalTransaction = Pick<CeloTxPending, 'to' | 'input' | 'value'>; export type Proposal = ProposalTransaction[]; export declare const proposalToParams: (proposal: Proposal, descriptionURL: string) => [values: (string | number)[], destinations: string[], data: string | number[], dataLengths: (string | number)[], descriptionUrl: string]; interface ApprovalStatus { completion: string; confirmations: string[]; approvers: string[]; } export interface ProposalRecord { metadata: ProposalMetadata; proposal: Proposal; stage: ProposalStage; approved: boolean; passed: boolean; upvotes?: BigNumber; approvals?: ApprovalStatus; votes?: Votes; } export interface UpvoteRecord { proposalID: BigNumber; upvotes: BigNumber; } export declare enum VoteValue { None = "None", Abstain = "Abstain", No = "No", Yes = "Yes" } export interface Votes { [VoteValue.Abstain]: BigNumber; [VoteValue.No]: BigNumber; [VoteValue.Yes]: BigNumber; } export type HotfixParams = Parameters<Governance['methods']['executeHotfix']>; export declare const hotfixToParams: (proposal: Proposal, salt: Buffer) => [values: (string | number)[], destinations: string[], data: string | number[], dataLengths: (string | number)[], salt: string | number[]]; export interface HotfixRecord { approved: boolean; councilApproved: boolean; executed: boolean; executionTimeLimit: BigNumber; } export interface VoteRecord { proposalID: BigNumber; votes: BigNumber; value: VoteValue; yesVotes: BigNumber; noVotes: BigNumber; abstainVotes: BigNumber; } export interface Voter { upvote: UpvoteRecord; votes: VoteRecord[]; refundedDeposits: BigNumber; } /** * Contract managing voting for governance proposals. */ export declare class GovernanceWrapper extends BaseWrapperForGoverning<Governance> { /** * Querying number of possible concurrent proposals. * @returns Current number of possible concurrent proposals. */ concurrentProposals: () => Promise<BigNumber>; /** * Query time of last proposal dequeue * @returns Time of last dequeue */ lastDequeue: () => Promise<BigNumber>; /** * Query proposal dequeue frequency. * @returns Current proposal dequeue frequency in seconds. */ dequeueFrequency: () => Promise<BigNumber>; /** * Query minimum deposit required to make a proposal. * @returns Current minimum deposit. */ minDeposit: () => Promise<BigNumber>; /** * Query queue expiry parameter. * @return The number of seconds a proposal can stay in the queue before expiring. */ queueExpiry: () => Promise<BigNumber>; /** * Query durations of different stages in proposal lifecycle. * @returns Durations for approval, referendum and execution stages in seconds. */ stageDurations(): Promise<DequeuedStageDurations>; /** * Returns the required ratio of yes:no votes needed to exceed in order to pass the proposal transaction. * @param tx Transaction to determine the constitution for running. */ getTransactionConstitution(tx: ProposalTransaction): Promise<BigNumber>; /** * Returns the required ratio of yes:no votes needed to exceed in order to pass the proposal. * @param proposal Proposal to determine the constitution for running. */ getConstitution(proposal: Proposal): Promise<BigNumber>; /** * Returns the participation parameters. * @returns The participation parameters. */ getParticipationParameters(): Promise<ParticipationParameters>; getSupportWithConstitutionThreshold(proposalID: BigNumber.Value, constitution: BigNumber): Promise<{ support: BigNumber; required: BigNumber; total: BigNumber; }>; getSupport(proposalID: BigNumber.Value): Promise<{ support: BigNumber; required: BigNumber; total: BigNumber; }>; /** * Returns whether or not a particular account is voting on proposals. * @param account The address of the account. * @returns Whether or not the account is voting on proposals. */ isVoting: (account: string) => Promise<boolean>; /** * Returns current configuration parameters. */ getConfig(): Promise<GovernanceConfig>; /** * @dev Returns human readable configuration of the governance contract * @return GovernanceConfig object */ getHumanReadableConfig(): Promise<{ dequeueFrequency: string; queueExpiry: string; stageDurations: { Referendum: string; Execution: string; }; concurrentProposals: BigNumber; minDeposit: BigNumber; participationParameters: ParticipationParameters; }>; /** * Returns the metadata associated with a given proposal. * @param proposalID Governance proposal UUID */ getProposalMetadata: (proposalID: BigNumber.Value) => Promise<ProposalMetadata>; /** * Returns the human readable metadata associated with a given proposal. * @param proposalID Governance proposal UUID */ getHumanReadableProposalMetadata(proposalID: BigNumber.Value): Promise<{ timestamp: string; proposer: string; deposit: BigNumber; transactionCount: number; descriptionURL: string; }>; /** * Returns the transaction at the given index associated with a given proposal. * @param proposalID Governance proposal UUID * @param txIndex Transaction index */ getProposalTransaction: (proposalID: BigNumber.Value, txIndex: number) => Promise<ProposalTransaction>; /** * Returns whether a given proposal is approved. * @param proposalID Governance proposal UUID */ isApproved: (proposalID: BigNumber.Value) => Promise<boolean>; /** * Returns whether a dequeued proposal is expired. * @param proposalID Governance proposal UUID */ isDequeuedProposalExpired: (proposalID: BigNumber.Value) => Promise<boolean>; /** * Returns whether a dequeued proposal is expired. * @param proposalID Governance proposal UUID */ isQueuedProposalExpired: (args_0: BigNumber.Value) => Promise<boolean>; /** * Returns the approver address for proposals and hotfixes. */ getApprover: () => Promise<`0x${string}`>; /** * Returns the approver multisig contract for proposals and hotfixes. */ getApproverMultisig: () => Promise<import("./MultiSig").MultiSigWrapper>; /** * Returns the security council address for hotfixes. */ getSecurityCouncil: () => Promise<`0x${string}`>; /** * Returns the security council multisig contract for hotfixes. */ getSecurityCouncilMultisig: () => Promise<import("./MultiSig").MultiSigWrapper>; getProposalStage: (proposalID: BigNumber.Value) => Promise<ProposalStage>; proposalSchedule(proposalID: BigNumber.Value): Promise<Partial<StageDurations<BigNumber>>>; humanReadableProposalSchedule(proposalID: BigNumber.Value): Promise<Partial<StageDurations<string>>>; /** * Returns the proposal associated with a given id. * @param proposalID Governance proposal UUID */ getProposal(proposalID: BigNumber.Value): Promise<Proposal>; getApprovalStatus(proposalID: BigNumber.Value): Promise<ApprovalStatus>; /** * Returns the stage, metadata, upvotes, votes, and transactions associated with a given proposal. * @param proposalID Governance proposal UUID */ getProposalRecord(proposalID: BigNumber.Value): Promise<ProposalRecord>; /** * Returns whether a given proposal is passing relative to the constitution's threshold. * @param proposalID Governance proposal UUID */ isProposalPassing: (args_0: BigNumber.Value) => Promise<boolean>; /** * Withdraws refunded proposal deposits. */ withdraw: () => import("@celo/connect").CeloTransactionObject<boolean>; /** * Submits a new governance proposal. * @param proposal Governance proposal * @param descriptionURL A URL where further information about the proposal can be viewed */ propose: (proposal: Proposal, descriptionURL: string) => import("@celo/connect").CeloTransactionObject<string>; /** * Returns whether a governance proposal exists with the given ID. * @param proposalID Governance proposal UUID */ proposalExists: (proposalID: BigNumber.Value) => Promise<boolean>; /** * Returns the current upvoted governance proposal ID and applied vote weight (zeroes if none). * @param upvoter Address of upvoter */ getUpvoteRecord: (upvoter: Address) => Promise<UpvoteRecord>; isUpvoting(upvoter: Address): Promise<boolean>; /** * Returns the corresponding vote record * @param voter Address of voter * @param proposalID Governance proposal UUID */ getVoteRecord(voter: Address, proposalID: BigNumber.Value): Promise<VoteRecord | null>; /** * Returns whether a given proposal is queued. * @param proposalID Governance proposal UUID */ isQueued: (args_0: BigNumber.Value) => Promise<boolean>; /** * Returns the value of proposal deposits that have been refunded. * @param proposer Governance proposer address. */ getRefundedDeposits: (args_0: string) => Promise<BigNumber>; getUpvotes: (args_0: BigNumber.Value) => Promise<BigNumber>; /** * Returns the yes, no, and abstain votes applied to a given proposal. * @param proposalID Governance proposal UUID */ getVotes: (args_0: BigNumber.Value) => Promise<Votes>; /** * Returns the proposal queue as list of upvote records. */ getQueue: () => Promise<UpvoteRecord[]>; /** * Returns the (existing) proposal dequeue as list of proposal IDs. */ getDequeue(filterZeroes?: boolean): Promise<BigNumber[]>; getVoteRecords(voter: Address): Promise<VoteRecord[]>; isVotingReferendum(voter: Address): Promise<boolean>; getVoter(account: Address): Promise<Voter>; /** * Dequeues any queued proposals if `dequeueFrequency` seconds have elapsed since the last dequeue */ dequeueProposalsIfReady: () => import("@celo/connect").CeloTransactionObject<void>; /** * Returns the number of votes that will be applied to a proposal for a given voter. * @param voter Address of voter */ getVoteWeight(voter: Address): Promise<BigNumber>; private getIndex; private getDequeueIndex; private getQueueIndex; private lesserAndGreater; sortedQueue(queue: UpvoteRecord[]): UpvoteRecord[]; private withUpvoteRevoked; private withUpvoteApplied; private lesserAndGreaterAfterRevoke; private lesserAndGreaterAfterUpvote; /** * Applies provided upvoter's upvote to given proposal. * @param proposalID Governance proposal UUID * @param upvoter Address of upvoter */ upvote(proposalID: BigNumber.Value, upvoter: Address): Promise<import("@celo/connect").CeloTransactionObject<boolean>>; /** * Revokes provided upvoter's upvote. * @param upvoter Address of upvoter */ revokeUpvote(upvoter: Address): Promise<import("@celo/connect").CeloTransactionObject<boolean>>; /** * Approves given proposal, allowing it to later move to `referendum`. * @param proposalID Governance proposal UUID * @notice Only the `approver` address will succeed in sending this transaction */ approve(proposalID: BigNumber.Value): Promise<import("@celo/connect").CeloTransactionObject<boolean>>; /** * Applies `sender`'s vote choice to a given proposal. * @param proposalID Governance proposal UUID * @param vote Choice to apply (yes, no, abstain) */ vote(proposalID: BigNumber.Value, vote: keyof typeof VoteValue): Promise<import("@celo/connect").CeloTransactionObject<boolean>>; /** * Applies `sender`'s vote choice to a given proposal. * @param proposalID Governance proposal UUID. * @param yesVotes The yes votes. * @param noVotes The no votes. * @param abstainVotes The abstain votes. */ votePartially(proposalID: BigNumber.Value, yesVotes: BigNumber.Value, noVotes: BigNumber.Value, abstainVotes: BigNumber.Value): Promise<import("@celo/connect").CeloTransactionObject<boolean>>; revokeVotes: () => import("@celo/connect").CeloTransactionObject<boolean>; /** * Executes a given proposal's associated transactions. * @param proposalID Governance proposal UUID */ execute(proposalID: BigNumber.Value): Promise<import("@celo/connect").CeloTransactionObject<boolean>>; getHotfixHash: (proposal: Proposal, salt: Buffer) => Promise<string>; /** * Returns approved, executed, and prepared status associated with a given hotfix. * @param hash keccak256 hash of hotfix's associated abi encoded transactions */ getHotfixRecord(hash: Buffer): Promise<HotfixRecord>; /** * Returns the number of validators required to reach a Byzantine quorum */ minQuorumSize: () => Promise<BigNumber>; /** * Marks the given hotfix approved by `sender`. * @param hash keccak256 hash of hotfix's associated abi encoded transactions * @notice Only the `approver` address will succeed in sending this transaction */ approveHotfix: (args_0: Buffer) => import("@celo/connect").CeloTransactionObject<void>; /** * Marks the given hotfix prepared for current epoch if quorum of validators have whitelisted it. * @param hash keccak256 hash of hotfix's associated abi encoded transactions */ prepareHotfix: (args_0: Buffer) => import("@celo/connect").CeloTransactionObject<void>; /** * Executes a given sequence of transactions if the corresponding hash is prepared and approved. * @param hotfix Governance hotfix proposal * @param salt Secret which guarantees uniqueness of hash * @notice keccak256 hash of abi encoded transactions computed on-chain */ executeHotfix: (proposal: Proposal, salt: Buffer) => import("@celo/connect").CeloTransactionObject<void>; } export type GovernanceWrapperType = GovernanceWrapper; export {};