GovernanceVotePower
#
Source | Inherits from IIGovernanceVotePower
Contract managing governance vote power and its delegation.
Functions#
constructor
#
constructor(
contract IVPToken _ownerToken,
contract IPChainStakeMirror _pChainStakeMirror
) public;
Construct GovernanceVotePower
for given VPToken
.
delegate
#
function delegate(
address _to
) public;
Delegates all governance vote power of msg.sender
to address _to
.
Parameters | Type | Description |
---|---|---|
_to |
address |
The address of the recipient. |
delegatedGovernanceVotePowerHistoryCleanup
#
function delegatedGovernanceVotePowerHistoryCleanup(
address _owner,
uint256 _count
) external returns (
uint256);
Delete governance vote power checkpoints that expired (i.e. are before cleanupBlockNumber
).
Method can only be called from the cleanerContract
(which may be a proxy to external cleaners).
Parameters | Type | Description |
---|---|---|
_owner |
address |
Vote power owner account address. |
_count |
uint256 |
Maximum number of checkpoints to delete. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
The number of deleted checkpoints. |
delegatesHistoryCleanup
#
function delegatesHistoryCleanup(
address _owner,
uint256 _count
) external returns (
uint256);
Delete delegates checkpoints that expired (i.e. are before cleanupBlockNumber
).
Method can only be called from the cleanerContract
(which may be a proxy to external cleaners).
Parameters | Type | Description |
---|---|---|
_owner |
address |
Vote power owner account address. |
_count |
uint256 |
Maximum number of checkpoints to delete. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
The number of deleted checkpoints. |
getCleanupBlockNumber
#
function getCleanupBlockNumber(
) external view returns (
uint256);
Get the current cleanup block number set with setCleanupBlockNumber
.
Returns | Type | Description |
---|---|---|
[0] | uint256 |
The currently set cleanup block number. |
getDelegateOfAt
#
function getDelegateOfAt(
address _who,
uint256 _blockNumber
) public view returns (
address);
Gets the address an account is delegating its governance vote power to, at a given block number.
Parameters | Type | Description |
---|---|---|
_who |
address |
The address being queried. |
_blockNumber |
uint256 |
The block number at which to fetch the address. |
Returns | Type | Description |
---|---|---|
[0] | address |
Address where _who was delegating its governance vote power at block _blockNumber . |
getDelegateOfAtNow
#
function getDelegateOfAtNow(
address _who
) public view returns (
address);
Gets the address an account is delegating its governance vote power to, at the latest block number.
Parameters | Type | Description |
---|---|---|
_who |
address |
The address being queried. |
Returns | Type | Description |
---|---|---|
[0] | address |
Address where _who is currently delegating its governance vote power. |
getVotes
#
function getVotes(
address _who
) public view returns (
uint256);
Gets the governance vote power of an address at the latest block, including all delegations made to it.
Parameters | Type | Description |
---|---|---|
_who |
address |
The address being queried. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
Governance vote power of account at the lastest block. |
ownerToken
#
function ownerToken(
) external view returns (
contract IVPToken);
Get the token that this governance vote power contract belongs to.
Returns | Type | Description |
---|---|---|
[0] | contract IVPToken |
The IVPToken interface owning this contract. |
pChainStakeMirror
#
function pChainStakeMirror(
) external view returns (
contract IPChainStakeMirror);
Get the stake mirror contract that this governance vote power contract belongs to.
Returns | Type | Description |
---|---|---|
[0] | contract IPChainStakeMirror |
The IPChainStakeMirror interface owning this contract. |
setCleanerContract
#
function setCleanerContract(
address _cleanerContract
) external;
Set the contract that is allowed to call history cleaning methods.
This method can be called by the ownerToken
only.
Parameters | Type | Description |
---|---|---|
_cleanerContract |
address |
Address of the cleanup contract. Usually this will be an instance of CleanupBlockNumberManager . |
setCleanupBlockNumber
#
function setCleanupBlockNumber(
uint256 _blockNumber
) external;
Set the cleanup block number.
Historic data for the blocks before cleanupBlockNumber
can be erased.
History before that block should never be used since it can be inconsistent.
In particular, cleanup block number must be lower than the current vote power block.
This method can be called by the ownerToken
only.
Parameters | Type | Description |
---|---|---|
_blockNumber |
uint256 |
The new cleanup block number. |
undelegate
#
function undelegate(
) public;
Undelegates all governance vote power of msg.sender
.
updateAtTokenTransfer
#
function updateAtTokenTransfer(
address _from,
address _to,
uint256,
uint256,
uint256 _amount
) external;
Update governance vote power of all involved delegates after tokens are transferred.
This function MUST be called after each governance token transfer for the delegates to reflect the correct balance.
Parameters | Type | Description |
---|---|---|
_from |
address |
Source address of the transfer. |
_to |
address |
Destination address of the transfer. |
`` | uint256 |
|
`` | uint256 |
|
_amount |
uint256 |
Amount being transferred. |
votePowerOfAt
#
function votePowerOfAt(
address _who,
uint256 _blockNumber
) public view returns (
uint256);
Gets the governance vote power of an address at a given block number, including all delegations made to it.
Parameters | Type | Description |
---|---|---|
_who |
address |
The address being queried. |
_blockNumber |
uint256 |
The block number at which to fetch the vote power. |
Returns | Type | Description |
---|---|---|
[0] | uint256 |
Governance vote power of _who at _blockNumber . |
Modifiers#
onlyCleaner
#
modifier onlyCleaner()
History cleaning methods can be called only from the cleaner address.
onlyOwnerContracts
#
modifier onlyOwnerContracts()
Method updateAtTokenTransfer
in GovernanceVotePower
can only be executed by the owner contracts.
onlyOwnerToken
#
modifier onlyOwnerToken()
All external methods in GovernanceVotePower
can only be executed by the owner token.
Variables#
cleanerContract
#
address cleanerContract
Address of the contract that is allowed to call methods for history cleaning.
Set with setCleanerContract
.
ownerToken
#
contract IVPToken ownerToken
The VPToken
and IPChainStakeMirror
contracts that own this GovernanceVotePower
.
All state changing methods may be called only from these addresses.
This is because original msg.sender
is typically sent in a parameter
and we must make sure that it cannot be faked by directly calling
GovernanceVotePower
methods.