Voting

Voting system for Oracle.

Handles receiving and resolving price requests via a commit-reveal voting scheme.

onlyRegisteredContract() modifier

MODIFIERS***

==== onlyIfNotMigrated() modifier

==== onlyOwner() modifier

Throws if called by any account other than the owner.

==== onlyIfTest() modifier

Reverts if not running in test mode.

==== constructor(uint256 _phaseLength, struct FixedPoint.Unsigned _gatPercentage, struct FixedPoint.Unsigned _inflationRate, uint256 _rewardsExpirationTimeout, address _votingToken, address _identifierWhitelist, address _finder, bool _isTest) public

Construct the Voting contract.

Parameters:

  • _phaseLength: length of the commit and reveal phases in seconds.

  • _gatPercentage: of the total token supply that must be used in a vote to create a valid price resolution.

  • _inflationRate: percentage inflation per round used to increase token supply of correct voters.

  • _rewardsExpirationTimeout: timeout, in seconds, within which rewards must be claimed.

  • _votingToken: address of the UMA token contract used to commit votes.

  • _identifierWhitelist: defines the identifiers that can have have synthetics created against.

  • _finder: keeps track of all contracts within the system based on their interfaceName.

  • _isTest: whether this contract is being constructed for the purpose of running automated tests.

==== requestPrice(bytes32 identifier, uint256 time) external

Enqueues a request (if a request isn’t already present) for the given identifier, time pair.

Time must be in the past and the identifier must be supported.

Parameters:

  • identifier: uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested.

  • time: unix timestamp of for the price request.

==== hasPrice(bytes32 identifier, uint256 time) → bool _hasPrice external

Whether the price for identifier and time is available.

Time must be in the past and the identifier must be supported.

Parameters:

  • identifier: uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested.

  • time: unix timestamp of for the price request.

==== getPrice(bytes32 identifier, uint256 time) → int256 external

Gets the price for identifier and time if it has already been requested and resolved.

If the price is not available, the method reverts.

Parameters:

  • identifier: uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested.

  • time: unix timestamp of for the price request.

==== getPriceRequestStatuses(struct VotingInterface.PendingRequest[] requests) → struct Voting.RequestState[] requestStates public

Gets the status of a list of price requests, identified by their identifier and time.

If the status for a particular request is NotRequested, the lastVotingRound will always be 0.

Parameters:

  • requests: array of time PendingRequest which includes a identifier and timestamp for each request.

==== commitVote(bytes32 identifier, uint256 time, bytes32 hash) public

Commit a vote for a price request for identifier at time.

identifier, time must correspond to a price request that’s currently in the commit phase. Commits can be changed.

Parameters:

  • identifier: uniquely identifies the committed vote. EG BTC/USD price pair.

  • time: unix timestamp of the price is being voted on.

  • hash: keccak256 hash of the price you want to vote for and a int salt.

==== revealVote(bytes32 identifier, uint256 time, int256 price, int256 salt) public

Reveal a previously committed vote for identifier at time.

The revealed price and salt must match the latest hash that commitVote() was called with. Only the committer can reveal their vote.

Parameters:

  • identifier: voted on in the commit phase. EG BTC/USD price pair.

  • time: specifies the unix timestamp of the price is being voted on.

  • price: voted on during the commit phase.

  • salt: value used to hide the commitment price during the commit phase.

==== commitAndPersistEncryptedVote(bytes32 identifier, uint256 time, bytes32 hash, bytes encryptedVote) public

commits a vote and stores an encrypted version which can be later decrypted to recover the voter’s price & salt.

The encryption mechanism uses encrypt from a signature from a users price key. See EncryptedSender.sol

Parameters:

  • identifier: unique price pair identifier. Eg: BTC/USD price pair.

  • time: unix timestamp of for the price request.

  • hash: keccak256 hash of the price you want to vote for and a int salt.

  • encryptedVote: offchain encrypted blob containing the voters amount, time and salt.

==== batchCommit(struct VotingInterface.Commitment[] commits) external

Submit a batch of commits in a single transaction.

Using encryptedVote is optional. If included then commitment is stored on chain. Look at project-root/common/Constants.js for the tested maximum number of commitments that can fit in one transaction.

Parameters:

  • commits: struct to encapsulate an identifier, time, hash and optional encryptedVote.

==== batchReveal(struct VotingInterface.Reveal[] reveals) external

Reveal multiple votes in a single transaction. Look at project-root/common/Constants.js for the tested maximum number of reveals. that can fit in one transaction.

For more information on reveals, review the comment for revealVote.

Parameters:

  • reveals: array of the Reveal struct which contains an identifier, time, price and salt.

==== retrieveRewards(address voterAddress, uint256 roundId, struct VotingInterface.PendingRequest[] toRetrieve) → struct FixedPoint.Unsigned totalRewardToIssue public

Retrieves rewards owed for a set of resolved price requests.

Can only retrieve rewards if calling for a valid round and if the call is done within the timeout threshold (not expired).

Parameters:

  • voterAddress: voter for which rewards will be retrieved. Does not have to be the caller.

  • roundId: the round from which voting rewards will be retrieved from.

  • toRetrieve: array of PendingRequests which rewards are retrieved from.

==== getPendingRequests() → struct VotingInterface.PendingRequest[] pendingRequests external

Gets the queries that are being voted on this round.

==== getVotePhase() → enum VotingInterface.Phase external

Returns the current voting phase, as a function of the current time.

==== getCurrentRoundId() → uint256 external

Returns the current round ID, as a function of the current time.

==== setMigrated(address newVotingAddress) external

Disables this Voting contract in favor of the migrated one.

Can only be called by the contract owner.

==== setInflationRate(struct FixedPoint.Unsigned newInflationRate) public

Resets the inflation rate. Note: this change only applies to rounds that have not yet begun.

This method is public because calldata structs are not currently supported by solidity.

Parameters:

  • newInflationRate: sets the next rounds inflation rate.

==== setGatPercentage(struct FixedPoint.Unsigned newGatPercentage) public

Resets the Gat percentage. Note: this change only applies to rounds that have not yet begun.

This method is public because calldata structs are not currently supported by solidity.

Parameters:

  • newGatPercentage: sets the next rounds Gat percentage.

==== setRewardsExpirationTimeout(uint256 NewRewardsExpirationTimeout) public

Resets the rewards expiration timeout.

This change only applies to rounds that have not yet begun.

Parameters:

  • NewRewardsExpirationTimeout: how long a caller can wait before choosing to withdraw their rewards.

==== getMessage(address user, bytes32 topicHash) → bytes external

Gets the current stored message corresponding to user and topicHash.

To decrypt messages (this requires access to the owner’s private keys), use the decryptMessage() function in common/Crypto.js.

Parameters:

  • user: address that stored this message.

  • topicHash: hash of the "subject" of the message.

==== storeMessage(bytes32 topicHash, bytes message) public

Stores a message categorized by a particular topicHash. This will overwrite the previous messages sent by this caller with this topicHash.

To construct an encrypted message, use the encryptMessage() in common/Crypto.js.

Parameters:

  • topicHash: hash of the "subject" or "topic" of the message.

  • message: the stored message.

==== removeMessage(bytes32 topicHash) public

Removes a stored message categorized by a particular topicHash.

Parameters:

  • topicHash: hash of the "subject" or "topic" of the message.

==== owner() → address public

Returns the address of the current owner.

==== isOwner() → bool public

Returns true if the caller is the current owner.

==== renounceOwnership() public

Leaves the contract without owner. It will not be possible to call onlyOwner functions anymore. Can only be called by the current owner.

Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.

==== transferOwnership(address newOwner) public

Transfers ownership of the contract to a new account (newOwner). Can only be called by the current owner.

==== _transferOwnership(address newOwner) internal

Transfers ownership of the contract to a new account (newOwner).

==== _msgSender() → address payable internal

==== _msgData() → bytes internal

==== setCurrentTime(uint256 _time) external

Sets the current time.

Will revert if not running in test mode.

==== getCurrentTime() → uint256 public

Gets the current time. Will return the last time set in setCurrentTime if running in test mode. Otherwise, it will return the block timestamp.

==== VoteCommitted(address voter, uint256 roundId, bytes32 identifier, uint256 time) event

EVENTS

VoteRevealed(address voter, uint256 roundId, bytes32 identifier, uint256 time, int256 price, uint256 numTokens) event

RewardsRetrieved(address voter, uint256 roundId, bytes32 identifier, uint256 time, uint256 numTokens) event

PriceRequestAdded(uint256 votingRoundId, bytes32 identifier, uint256 time) event

PriceResolved(uint256 resolutionRoundId, bytes32 identifier, uint256 time, int256 price) event

OwnershipTransferred(address previousOwner, address newOwner) event

© UMA Project 2018-2019