DelegationLogicLibrary

Git Source

Functions

checkpointDelegator

Used by _mint, _transferFrom, _burn and delegate to update delegator voting checkpoints. Automatically dedelegates, then updates checkpoint.

This function depends on _locked and must be called prior to token state changes. If you wish to dedelegate only, use _delegate(tokenId, 0) instead.

function checkpointDelegator(
    mapping(uint256 => IVotingEscrow.LockedBalance) storage _locked,
    mapping(uint256 => uint48) storage _numCheckpoints,
    mapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint)) storage
        _checkpoints,
    mapping(uint256 => uint256) storage _delegates,
    uint256 _delegator,
    uint256 _delegatee,
    address _owner
) external;

Parameters

NameTypeDescription
_lockedmapping(uint256 => IVotingEscrow.LockedBalance)State of all locked balances
_numCheckpointsmapping(uint256 => uint48)State of all user checkpoint counts
_checkpointsmapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint))State of all user checkpoints
_delegatesmapping(uint256 => uint256)State of all user delegatees
_delegatoruint256The delegator to update checkpoints for
_delegateeuint256The new delegatee for the delegator. Cannot be equal to _delegator (use 0 instead).
_owneraddressThe new (or current) owner for the delegator

checkpointDelegatee

Update delegatee's delegatedBalance by balance. Only updates if delegating to a new delegatee.

If used with balance == _locked[_tokenId].amount, then this is the same as delegating or dedelegating from _tokenId If used with balance < _locked[_tokenId].amount, then this is used to adjust delegatedBalance when a user's balance is modified (e.g. increaseAmount, merge etc). If delegatee is 0 (i.e. user is not delegating), then do nothing.

function checkpointDelegatee(
    mapping(uint256 => uint48) storage _numCheckpoints,
    mapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint)) storage
        _checkpoints,
    uint256 _delegatee,
    uint256 balance_,
    bool _increase
) public;

Parameters

NameTypeDescription
_numCheckpointsmapping(uint256 => uint48)State of all user checkpoint counts
_checkpointsmapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint))State of all user checkpoints
_delegateeuint256The delegatee's tokenId
balance_uint256The delta in balance change
_increaseboolTrue if balance is increasing, false if decreasing

_isCheckpointInNewBlock

function _isCheckpointInNewBlock(
    mapping(uint256 => uint48) storage _numCheckpoints,
    mapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint)) storage
        _checkpoints,
    uint256 _tokenId
) internal view returns (bool);

getPastVotesIndex

Binary search to get the voting checkpoint for a token id at or prior to a given timestamp.

If a checkpoint does not exist prior to the timestamp, this will return 0.

function getPastVotesIndex(
    mapping(uint256 => uint48) storage _numCheckpoints,
    mapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint)) storage
        _checkpoints,
    uint256 _tokenId,
    uint256 _timestamp
) internal view returns (uint48);

Parameters

NameTypeDescription
_numCheckpointsmapping(uint256 => uint48)State of all user checkpoint counts
_checkpointsmapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint))State of all user checkpoints
_tokenIduint256.
_timestampuint256.

Returns

NameTypeDescription
<none>uint48The index of the checkpoint.

getPastVotes

Retrieves historical voting balance for a token id at a given timestamp.

If a checkpoint does not exist prior to the timestamp, this will return 0. The user must also own the token at the time in order to receive a voting balance.

function getPastVotes(
    mapping(uint256 => uint48) storage _numCheckpoints,
    mapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint)) storage
        _checkpoints,
    address _account,
    uint256 _tokenId,
    uint256 _timestamp
) external view returns (uint256);

Parameters

NameTypeDescription
_numCheckpointsmapping(uint256 => uint48)State of all user checkpoint counts
_checkpointsmapping(uint256 => mapping(uint48 => IVotingEscrow.Checkpoint))State of all user checkpoints
_accountaddress.
_tokenIduint256.
_timestampuint256.

Returns

NameTypeDescription
<none>uint256Total voting balance including delegations at a given timestamp.