Skip to content

VPContract#

Source | Inherits from IIVPContract, Delegatable

Helper contract handling all the vote power and delegation functionality for an associated VPToken.

Functions#

batchVotePowerOfAt#

Defined in VPContract (Docs, Source).

function batchVotePowerOfAt(
    address[] _owners,
    uint256 _blockNumber
) external view returns (
    uint256[] _votePowers);

Get the vote power of a set of addresses at a given block number.

Parameters Type Description
_owners address[] The list of addresses being queried.
_blockNumber uint256 The block number being queried.
Returns Type Description
_votePowers uint256[] Vote power of each address at _blockNumber, including any delegation received.

cleanupBlockNumber#

Defined in VPContract (Docs, Source).

function cleanupBlockNumber(
) external view returns (
    uint256);

Get the current cleanup block number set with setCleanupBlockNumber.

Returns Type Description
[0] uint256 The currently set cleanup block number.

constructor#

Defined in VPContract (Docs, Source).

constructor(
    contract IVPToken _ownerToken,
    bool _isReplacement
) public;

Construct VPContract for given VPToken.

delegate#

Defined in VPContract (Docs, Source).

function delegate(
    address _from,
    address _to,
    uint256 _balance,
    uint256 _bips
) external;

Delegate _bips percentage of voting power from a delegator address to a delegatee address.

Parameters Type Description
_from address The address of the delegator.
_to address The address of the delegatee.
_balance uint256 The delegator's current balance
_bips uint256 The percentage of voting power to be delegated expressed in basis points (1/100 of one percent). Not cumulative: every call resets the delegation value (and a value of 0 revokes delegation).

delegateExplicit#

Defined in VPContract (Docs, Source).

function delegateExplicit(
    address _from,
    address _to,
    uint256 _balance,
    uint256 _amount
) external;

Explicitly delegate _amount tokens of voting power from a delegator address to a delegatee address.

Parameters Type Description
_from address The address of the delegator.
_to address The address of the delegatee.
_balance uint256 The delegator's current balance.
_amount uint256 An explicit vote power amount to be delegated. Not cumulative: every call resets the delegation value (and a value of 0 undelegates _to).

delegatesOf#

Defined in VPContract (Docs, Source).

function delegatesOf(
    address _owner
) external view returns (
    address[] _delegateAddresses,
    uint256[] _bips,
    uint256 _count,
    uint256 _delegationMode);

Get the percentages and addresses being delegated to by a vote power delegator.

Parameters Type Description
_owner address The address of the delegator being queried.
Returns Type Description
_delegateAddresses address[] Array of delegatee addresses.
_bips uint256[] Array of delegation percents specified in basis points (1/100 or 1 percent), for each delegatee.
_count uint256 The number of returned delegatees.
_delegationMode uint256 The mode of the delegation (NOTSET=0, PERCENTAGE=1, AMOUNT=2). See Delegatable.DelegationMode.

delegatesOfAt#

Defined in VPContract (Docs, Source).

function delegatesOfAt(
    address _owner,
    uint256 _blockNumber
) public view returns (
    address[] _delegateAddresses,
    uint256[] _bips,
    uint256 _count,
    uint256 _delegationMode);

Get the percentages and addresses being delegated to by a vote power delegator, at a given block.

Parameters Type Description
_owner address The address of the delegator being queried.
_blockNumber uint256 The block number being queried.
Returns Type Description
_delegateAddresses address[] Array of delegatee addresses.
_bips uint256[] Array of delegation percents specified in basis points (1/100 or 1 percent), for each delegatee.
_count uint256 The number of returned delegatees.
_delegationMode uint256 The mode of the delegation (NOTSET=0, PERCENTAGE=1, AMOUNT=2). See Delegatable.DelegationMode.

delegationModeOf#

Defined in VPContract (Docs, Source).

function delegationModeOf(
    address _who
) external view returns (
    uint256);

Get the delegation mode of an address. This mode determines whether vote power is allocated by percentage or by explicit value and cannot be changed once set with delegate or delegateExplicit.

Parameters Type Description
_who address The address being queried.
Returns Type Description
[0] uint256 Delegation mode (NOTSET=0, PERCENTAGE=1, AMOUNT=2). See Delegatable.DelegationMode.

explicitDelegationHistoryCleanup#

Defined in Delegatable (Docs, Source).

function explicitDelegationHistoryCleanup(
    address _from,
    address _to,
    uint256 _count
) external returns (
    uint256);

Delete explicit delegation 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
_from address Delegator address.
_to address Delegatee address.
_count uint256 Maximum number of checkpoints to delete.
Returns Type Description
[0] uint256 Number of checkpoints deleted.

isReplacement#

Defined in IIVPContract (Docs, Source).

function isReplacement(
) external view returns (
    bool);

Return true if this IIVPContract is configured to be used as a replacement for other contract. It means that vote powers are not necessarily correct at the initialization, therefore every method that reads vote power must check whether it is initialized for that address and block.

ownerToken#

Defined in IIVPContract (Docs, Source).

function ownerToken(
) external view returns (
    contract IVPToken);

The VPToken (or some other contract) that owns this VPContract. All state changing methods may be called only from this address. 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 IIVPContract methods. Owner token is also used in case of replacement to recover vote powers from balances.

percentageDelegationHistoryCleanup#

Defined in Delegatable (Docs, Source).

function percentageDelegationHistoryCleanup(
    address _owner,
    uint256 _count
) external returns (
    uint256);

Delete percentage delegation 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 Balance owner account address.
_count uint256 Maximum number of checkpoints to delete.
Returns Type Description
[0] uint256 Number of deleted checkpoints.

revocationCleanup#

Defined in Delegatable (Docs, Source).

function revocationCleanup(
    address _from,
    address _to,
    uint256 _blockNumber
) external returns (
    uint256);

Delete revocation entry that expired (i.e. is before cleanupBlockNumber). Method can only be called from the cleanerContract (which may be a proxy to external cleaners).

Parameters Type Description
_from address Delegator address.
_to address Delegatee address.
_blockNumber uint256 Block number for which total supply value was cached.
Returns Type Description
[0] uint256 Number of revocation entries deleted (always 0 or 1).

revokeDelegationAt#

Defined in VPContract (Docs, Source).

function revokeDelegationAt(
    address _from,
    address _to,
    uint256 _balance,
    uint256 _blockNumber
) external;

Revoke all vote power delegation from a delegator address to a delegatee address at a given block. Only affects the reads via votePowerOfAtCached in the block _blockNumber. This method should be used only to prevent rogue delegate voting in the current voting block. To stop delegating use delegate or delegateExplicit with value of 0, or undelegateAll/ undelegateAllExplicit.

Parameters Type Description
_from address The address of the delegator.
_to address Address of the delegatee.
_balance uint256 The delegator's current balance.
_blockNumber uint256 The block number at which to revoke delegation. Must be in the past.

setCleanerContract#

Defined in VPContract (Docs, Source).

function setCleanerContract(
    address _cleanerContract
) external;

Set the contract that is allowed to call history cleaning methods.

Parameters Type Description
_cleanerContract address Address of the cleanup contract. Usually this will be an instance of CleanupBlockNumberManager.

setCleanupBlockNumber#

Defined in VPContract (Docs, Source).

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.

The method can be called only by the owner token.

Parameters Type Description
_blockNumber uint256 The new cleanup block number.

undelegateAll#

Defined in VPContract (Docs, Source).

function undelegateAll(
    address _from,
    uint256 _balance
) external;

Undelegate all voting power for a delegator address. Can only be used with percentage delegation. Does not reset delegation mode back to NOTSET.

Parameters Type Description
_from address The address of the delegator.
_balance uint256 The delegator's current balance.

undelegateAllExplicit#

Defined in VPContract (Docs, Source).

function undelegateAllExplicit(
    address _from,
    address[] _delegateAddresses
) external returns (
    uint256);

Undelegate all explicit vote power by amount for a delegator address. Can only be used with explicit delegation. Does not reset delegation mode back to NOTSET.

Parameters Type Description
_from address The address of the delegator.
_delegateAddresses address[] Explicit delegation does not store delegatees' addresses, so the caller must supply them.
Returns Type Description
[0] uint256 The amount still delegated (in case the list of delegates was incomplete).

undelegatedVotePowerOf#

Defined in VPContract (Docs, Source).

function undelegatedVotePowerOf(
    address _owner,
    uint256 _balance
) external view returns (
    uint256);

Compute the current undelegated vote power of an address.

Parameters Type Description
_owner address The address being queried.
_balance uint256 Current balance of that address.
Returns Type Description
[0] uint256 The unallocated vote power of _owner, this is, the amount of vote power currently not being delegated to other addresses.

undelegatedVotePowerOfAt#

Defined in VPContract (Docs, Source).

function undelegatedVotePowerOfAt(
    address _owner,
    uint256 _balance,
    uint256 _blockNumber
) external view returns (
    uint256);

Compute the undelegated vote power of an address at a given block.

Parameters Type Description
_owner address The address being queried.
_balance uint256
_blockNumber uint256 The block number being queried.
Returns Type Description
[0] uint256 The unallocated vote power of _owner, this is, the amount of vote power that was not being delegated to other addresses at that block number.

updateAtTokenTransfer#

Defined in VPContract (Docs, Source).

function updateAtTokenTransfer(
    address _from,
    address _to,
    uint256 _fromBalance,
    uint256 _toBalance,
    uint256 _amount
) external;

Update vote powers when tokens are transferred. Also update delegated vote powers for percentage delegation and check for enough funds for explicit delegations.

Parameters Type Description
_from address Source account of the transfer.
_to address Destination account of the transfer.
_fromBalance uint256 Balance of the source account before the transfer.
_toBalance uint256 Balance of the destination account before the transfer.
_amount uint256 Amount that has been transferred.

votePowerCacheCleanup#

Defined in Delegatable (Docs, Source).

function votePowerCacheCleanup(
    address _owner,
    uint256 _blockNumber
) external returns (
    uint256);

Delete vote power cache entry that expired (i.e. is 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.
_blockNumber uint256 Block number for which total supply value was cached.
Returns Type Description
[0] uint256 Number of deleted cache entries (always 0 or 1).

votePowerFromTo#

Defined in VPContract (Docs, Source).

function votePowerFromTo(
    address _from,
    address _to,
    uint256 _balance
) external view returns (
    uint256);

Get current delegated vote power from a delegator to a delegatee.

Parameters Type Description
_from address Address of the delegator.
_to address Address of the delegatee.
_balance uint256 The delegator's current balance.
Returns Type Description
[0] uint256 The delegated vote power.

votePowerFromToAt#

Defined in VPContract (Docs, Source).

function votePowerFromToAt(
    address _from,
    address _to,
    uint256 _balance,
    uint256 _blockNumber
) external view returns (
    uint256);

Get delegated the vote power from a delegator to a delegatee at a given block number.

Parameters Type Description
_from address Address of the delegator.
_to address Address of the delegatee.
_balance uint256 The delegator's current balance.
_blockNumber uint256 The block number being queried.
Returns Type Description
[0] uint256 The delegated vote power.

votePowerHistoryCleanup#

Defined in Delegatable (Docs, Source).

function votePowerHistoryCleanup(
    address _owner,
    uint256 _count
) external returns (
    uint256);

Delete 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 Number of deleted checkpoints.

votePowerOf#

Defined in VPContract (Docs, Source).

function votePowerOf(
    address _who
) external view returns (
    uint256);

Get the current vote power of an address.

Parameters Type Description
_who address The address being queried.
Returns Type Description
[0] uint256 Current vote power of _who, including any delegation received.

votePowerOfAt#

Defined in VPContract (Docs, Source).

function votePowerOfAt(
    address _who,
    uint256 _blockNumber
) public view returns (
    uint256);

Get the vote power of an address at a given block number

Parameters Type Description
_who address The address being queried.
_blockNumber uint256 The block number being queried.
Returns Type Description
[0] uint256 Vote power of _who at _blockNumber, including any delegation received.

votePowerOfAtCached#

Defined in VPContract (Docs, Source).

function votePowerOfAtCached(
    address _who,
    uint256 _blockNumber
) external returns (
    uint256);

Get the vote power of an address at a given block number. Reads/updates cache and upholds revocations.

Parameters Type Description
_who address The address being queried.
_blockNumber uint256 The block number being queried.
Returns Type Description
[0] uint256 Vote power of _who at _blockNumber, including any delegation received.

votePowerOfAtIgnoringRevocation#

Defined in VPContract (Docs, Source).

function votePowerOfAtIgnoringRevocation(
    address _who,
    uint256 _blockNumber
) external view returns (
    uint256);

Get the vote power of an address at a given block number, ignoring revocation information and cache.

Parameters Type Description
_who address The address being queried.
_blockNumber uint256 The block number being queried.
Returns Type Description
[0] uint256 Vote power of _who at _blockNumber, including any delegation received. Result doesn't change if vote power is revoked.

Modifiers#

notBeforeCleanupBlock#

Defined in Delegatable (Docs, Source).

modifier notBeforeCleanupBlock(    uint256 _blockNumber)

Reading from history is not allowed before cleanupBlockNumber, since data before that might have been deleted and is thus unreliable.

Parameters Type Description
_blockNumber uint256 The block number being checked for validity.

onlyCleaner#

Defined in Delegatable (Docs, Source).

modifier onlyCleaner()

History cleaning methods can be called only from cleanerContract.

onlyExplicit#

Defined in VPContract (Docs, Source).

modifier onlyExplicit(    address sender)

If a delegate cannot be added by explicit amount, revert.

onlyOwnerToken#

Defined in VPContract (Docs, Source).

modifier onlyOwnerToken()

All external methods in VPContract can only be executed by the owner token.

onlyPercent#

Defined in VPContract (Docs, Source).

modifier onlyPercent(    address sender)

If a delegate cannot be added by percentage, revert.

Variables#

cleanerContract#

Defined in Delegatable (Docs, Source).

    address cleanerContract

Address of the contract that is allowed to call methods for history cleaning.

isReplacement#

Defined in VPContract (Docs, Source).

    bool isReplacement

Return true if this IIVPContract is configured to be used as a replacement for other contract. It means that vote powers are not necessarily correct at the initialization, therefore every method that reads vote power must check whether it is initialized for that address and block.

ownerToken#

Defined in VPContract (Docs, Source).

    contract IVPToken ownerToken

The VPToken (or some other contract) that owns this VPContract. All state changing methods may be called only from this address. 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 IIVPContract methods. Owner token is also used in case of replacement to recover vote powers from balances.


Last update: 2024-03-01