Voting

Voting system for Oracle.

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

onlyRegisteredDerivative() modifier

onlyRoleHolder(uint256 roleId) modifier

Reverts unless the caller is a member of the specified roleId.

onlyRoleManager(uint256 roleId) modifier

Reverts unless the caller is a member of the manager role for the specified roleId.

onlyExclusive(uint256 roleId) modifier

Reverts unless the roleId represents an initialized, exclusive roleId.

onlyShared(uint256 roleId) modifier

Reverts unless the roleId represents an initialized, shared roleId.

onlyValidRole(uint256 roleId) modifier

Reverts if roleId is not initialized.

onlyInvalidRole(uint256 roleId) modifier

Reverts if roleId is initialized.

onlyIfTest() modifier

Reverts if not running in test mode.

constructor(uint256 phaseLength, struct FixedPoint.Unsigned _gatPercentage, struct FixedPoint.Unsigned _inflationRate, address _votingToken, address _finder, bool _isTest) public

Construct the Voting contract.

Parameters:

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

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

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

requestPrice(bytes32 identifier, uint256 time) → uint256 expectedTime external

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

Returns the time at which the user should expect the price to be resolved. 0 means the price has already been resolved.

batchCommit(struct Voting.Commitment[] commits) external

batchReveal(struct Voting.Reveal[] reveals) external

addSupportedIdentifier(bytes32 identifier) external

Adds the provided identifier as a supported identifier.

isIdentifierSupported(bytes32 identifier) → bool external

Whether the Oracle provides prices for this identifier.

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

Whether the price for identifier and time is available.

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.

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

Gets the queries that are being voted on this round.

getVotePhase() → enum VoteTiming.Phase external

Gets the current vote phase (commit or reveal) based on the current block time.

getCurrentRoundId() → uint256 external

Gets the current vote round id based on the current block time.

hasRevealedVote(bytes32 identifier, uint256 time) → bool external

Whether the caller has a revealed vote for the current round for an (identifier, time).

If the price request was resolved in a previous round, this function will return false even if the caller did reveal a vote.

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

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

(identifier, time) must correspond to a price request that’s currently in the commit phase. hash should be the keccak256 hash of the price you want to vote for and a int salt. Commits can be changed.

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.

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

setInflationRate(struct FixedPoint.Unsigned _inflationRate) 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.

retrieveRewards(uint256 roundId, struct VotingInterface.PendingRequest[] toRetrieve) public

Retrieves rewards owed for a set of resolved price requests.

initializeOnce(uint256 phaseLength, struct FixedPoint.Unsigned _gatPercentage, struct FixedPoint.Unsigned _inflationRate) public

addAuthorizedSender(address sender) external

Authorizes sender to send messages to the caller.

removeAuthorizedSender(address sender) external

Revokes `sender’s authorization to send messages to the caller.

getMessage(address recipient, bytes32 topicHash) → bytes external

Gets the current stored message corresponding to recipient and topicHash.

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

getPublicKey(address recipient, bytes32 topicHash) → bytes external

Gets the stored public key for a particular recipient and topicHash. Return value will be 0 length if no public key has been set.

Senders may need this public key to encrypt messages that only the recipient can read. If the public key is communicated offchain, this field may be left empty.

sendMessage(address recipient_, bytes32 topicHash, bytes message) public

Sends message to recipient_ categorized by a particular topicHash. This will overwrite any previous messages sent to this recipient with this topicHash.

To construct an encrypted message, use the encryptMessage() in common/Crypto.js. The public key for the recipient can be obtained using the getPublicKey() method.

removeMessage(address recipient_, bytes32 topicHash) public

setPublicKey(bytes publicKey, bytes32 topicHash) public

Sets the public key for this caller and topicHash.

Note: setting the public key is optional - if the publicKey is communicated or can be derived offchain by the sender, there is no need to set it here. Because there are no specific requirements for the publicKey, there is also no verification of its validity other than its length.

isAuthorizedSender(address sender, address recipient) → bool public

Returns true if the sender is authorized to send to the recipient.

holdsRole(uint256 roleId, address memberToCheck) → bool public

Whether memberToCheck is a member of roleId.

Reverts if roleId does not correspond to an initialized role.

resetMember(uint256 roleId, address newMember) public

Changes the exclusive role holder of roleId to newMember.

Reverts if the caller is not a member of the managing role for roleId or if roleId is not an initialized, exclusive role.

getMember(uint256 roleId) → address public

Gets the current holder of the exclusive role, roleId.

Reverts if roleId does not represent an initialized, exclusive role.

addMember(uint256 roleId, address newMember) public

Adds newMember to the shared role, roleId.

Reverts if roleId does not represent an initialized, shared role or if the caller is not a member of the managing role for roleId.

removeMember(uint256 roleId, address memberToRemove) public

Removes memberToRemove from the shared role, roleId.

Reverts if roleId does not represent an initialized, shared role or if the caller is not a member of the managing role for roleId.

_createSharedRole(uint256 roleId, uint256 managingRoleId, address[] initialMembers) internal

Internal method to initialize a shared role, roleId, which will be managed by managingRoleId. initialMembers will be immediately added to the role.

Should be called by derived contracts, usually at construction time. Will revert if the role is already initialized.

_createExclusiveRole(uint256 roleId, uint256 managingRoleId, address initialMember) internal

Internal method to initialize a exclusive role, roleId, which will be managed by managingRoleId. initialMembers will be immediately added to the role.

Should be called by derived contracts, usually at construction time. Will revert if the role is already initialized.

constructor(bool _isTest) 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

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

RewardsRetrieved(address voter, uint256 rewardsRoundId, uint256 numTokens) event

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

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

SupportedIdentifierAdded(bytes32 identifier) event

© UMA Project 2018-2019