VotingV2
VotingV2
#
Handles receiving and resolving price requests via a commit-reveal voting scheme.
#
Functionsconstructor(uint256 _emissionRate, uint256 _unstakeCoolDown, uint256 _phaseLength, uint256 _minRollToNextRoundLength, struct FixedPoint.Unsigned _gatPercentage, address _votingToken, address _finder, address _timerAddress, address _slashingLibrary) (public)
updateTrackers(address voterAddress) (public)
_updateTrackers(address voterAddress) (internal)
_updateAccountSlashingTrackers(address voterAddress) (internal)
applySlashToVoter(int256 slash, address voterAddress) (internal)
_updateCumulativeSlashingTrackers() (internal)
signalRequestsAsSpamForDeletion(uint256[2][] spamRequestIndices) (public)
executeSpamDeletion(uint256 proposalId) (public)
setSpamDeletionProposalBond(uint256 _spamDeletionProposalBond) (public)
getSpamDeletionRequest(uint256 spamDeletionRequestId) β struct VotingV2.SpamDeletionRequest (public)
requestPrice(bytes32 identifier, uint256 time, bytes ancillaryData) (public)
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. The length of the ancillary data is limited such that this method abides by the EVM transaction gas limit.
#
Parameters:- identifier: uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested.
- time: unix timestamp for the price request.
- ancillaryData: arbitrary data appended to a price request to give the voters more info from the caller.
requestGovernanceAction(bytes32 identifier, uint256 time) (public)
Enqueues a governance action 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. The length of the ancillary data is limited such that this method abides by the EVM transaction gas limit.
#
Parameters:- identifier: uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested.
- time: unix timestamp for the price request.
_requestPrice(bytes32 identifier, uint256 time, bytes ancillaryData, bool isGovernance) (internal)
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. The length of the ancillary data is limited such that this method abides by the EVM transaction gas limit.
#
Parameters:- identifier: uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested.
- time: unix timestamp for the price request.
- ancillaryData: arbitrary data appended to a price request to give the voters more info from the caller.
- isGovernance: indicates whether the request is for a governance action.
requestPrice(bytes32 identifier, uint256 time) (public)
hasPrice(bytes32 identifier, uint256 time, bytes ancillaryData) β bool (public)
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.
- ancillaryData: arbitrary data appended to a price request to give the voters more info from the caller.
hasPrice(bytes32 identifier, uint256 time) β bool (public)
getPrice(bytes32 identifier, uint256 time, bytes ancillaryData) β int256 (public)
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.
- ancillaryData: arbitrary data appended to a price request to give the voters more info from the caller.
getPrice(bytes32 identifier, uint256 time) β int256 (public)
getPriceRequestStatuses(struct VotingAncillaryInterface.PendingRequestAncillary[] requests) β struct VotingV2.RequestState[] (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 type PendingRequest which includes an identifier and timestamp for each request.
getPriceRequestStatuses(struct VotingV2Interface.PendingRequest[] requests) β struct VotingV2.RequestState[] (public)
commitVote(bytes32 identifier, uint256 time, bytes ancillaryData, 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.
Since transaction data is public, the salt will be revealed with the vote. While this is the systemβs
expected behavior, voters should never reuse salts. If someone else is able to guess the voted price and knows
that a salt will be reused, then they can determine the vote pre-reveal.
#
Parameters:- identifier: uniquely identifies the committed vote. EG BTC/USD price pair.
- time: unix timestamp of the price being voted on.
- ancillaryData: arbitrary data appended to a price request to give the voters more info from the caller.
- hash: keccak256 hash of the
price
,salt
, voteraddress
,time
, currentroundId
, andidentifier
. /
commitVote(bytes32 identifier, uint256 time, bytes32 hash) (public)
snapshotCurrentRound(bytes signature) (external)
revealVote(bytes32 identifier, uint256 time, int256 price, bytes ancillaryData, int256 salt) (public)
Reveal a previously committed vote for identifier
at time
.
The revealed price
, salt
, address
, time
, roundId
, and identifier
, must hash to 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 being voted on.
- price: voted on during the commit phase.
- ancillaryData: arbitrary data appended to a price request to give the voters more info from the caller.
- salt: value used to hide the commitment price during the commit phase. /
revealVote(bytes32 identifier, uint256 time, int256 price, int256 salt) (public)
commitAndEmitEncryptedVote(bytes32 identifier, uint256 time, bytes ancillaryData, bytes32 hash, bytes encryptedVote) (public)
commits a vote and logs an event with a data blob, typically an encrypted version of the vote
An encrypted version of the vote is emitted in an event EncryptedVote
to allow off-chain infrastructure to
retrieve the commit. The contents of encryptedVote
are never used on chain: it is purely for convenience.
#
Parameters:- identifier: unique price pair identifier. Eg: BTC/USD price pair.
- time: unix timestamp of for the price request.
- ancillaryData: arbitrary data appended to a price request to give the voters more info from the caller.
- hash: keccak256 hash of the price you want to vote for and a
int256 salt
.
- encryptedVote: offchain encrypted blob containing the voters amount, time and salt. /
commitAndEmitEncryptedVote(bytes32 identifier, uint256 time, bytes32 hash, bytes encryptedVote) (public)
batchCommit(struct VotingAncillaryInterface.CommitmentAncillary[] commits) (public)
Submit a batch of commits in a single transaction.
Using encryptedVote
is optional. If included then commitment is emitted in an event.
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 optionalencryptedVote
. /
batchCommit(struct VotingV2Interface.Commitment[] commits) (public)
batchReveal(struct VotingAncillaryInterface.RevealAncillary[] reveals) (public)
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 info on reveals, review the comment for revealVote
.
#
Parameters:- reveals: array of the Reveal struct which contains an identifier, time, price and salt. /
batchReveal(struct VotingV2Interface.Reveal[] reveals) (public)
getPendingRequests() β struct VotingAncillaryInterface.PendingRequestAncillary[] (external)
Gets the queries that are being voted on this round.
getVotePhase() β enum VotingAncillaryInterface.Phase (public)
Returns the current voting phase, as a function of the current time.
getCurrentRoundId() β uint256 (public)
Returns the current round ID, as a function of the current time.
getRoundEndTime(uint256 roundId) β uint256 (public)
getNumberOfPriceRequests() β uint256 (public)
retrieveRewards(address voterAddress, uint256 roundId, struct VotingAncillaryInterface.PendingRequestAncillary[] toRetrieve) β struct FixedPoint.Unsigned (public)
setMigrated(address newVotingAddress) (external)
Disables this Voting contract in favor of the migrated one.
Can only be called by the contract owner.
#
Parameters:- newVotingAddress: the newly migrated contract address. /
setInflationRate(struct FixedPoint.Unsigned newInflationRate) (public)
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 round's Gat percentage. /
setRewardsExpirationTimeout(uint256 NewRewardsExpirationTimeout) (public)
setSlashingLibrary(address _newSlashingLibrary) (public)
Changes the slashing library used by this contract.
#
Parameters:- _newSlashingLibrary: new slashing library address. /
_getPriceOrError(bytes32 identifier, uint256 time, bytes ancillaryData) β bool, int256, string (internal)
_computeGat(uint256 roundId) β struct FixedPoint.Unsigned (internal)
stake(uint256 amount) (public)
requestUnstake(uint256 amount) (public)
executeUnstake() (public)
withdrawRewards() β uint256 (public)
exit() (public)
_updateReward(address voterAddress) (internal)
outstandingRewards(address voterAddress) β uint256 (public)
rewardPerToken() β uint256 (public)
setEmissionRate(uint256 _emissionRate) (public)
setUnstakeCoolDown(uint256 _unstakeCoolDown) (public)
setCurrentTime(uint256 time) (external)
Sets the current time.
Will revert if not running in test mode.
#
Parameters:- time: timestamp to set current Testable time to.
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.
owner() β address (public)
Returns the address of 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.
NOTE: 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
).
Internal function without access restriction.
_msgSender() β address (internal)
_msgData() β bytes (internal)
votingToken() β contract VotingToken (external)
#
EventsVoteCommitted(address voter, uint256 roundId, bytes32 identifier, uint256 time, bytes ancillaryData)
EncryptedVote(address voter, uint256 roundId, bytes32 identifier, uint256 time, bytes ancillaryData, bytes encryptedVote)
VoteRevealed(address voter, uint256 roundId, bytes32 identifier, uint256 time, int256 price, bytes ancillaryData, uint256 numTokens)
RewardsRetrieved(address voter, uint256 roundId, bytes32 identifier, uint256 time, bytes ancillaryData, uint256 numTokens)
PriceRequestAdded(uint256 roundId, bytes32 identifier, uint256 time, bytes ancillaryData)
PriceResolved(uint256 roundId, bytes32 identifier, uint256 time, int256 price, bytes ancillaryData)
OwnershipTransferred(address previousOwner, address newOwner)
#
ModifiersonlyRegisteredContract()
onlyIfNotMigrated()
onlyIfTest()
Reverts if not running in test mode.
onlyOwner()
Throws if called by any account other than the owner.