VotingEscrow
Inherits: HistoricalBalance, IMaverickV2VotingEscrowBase, ReentrancyGuard, Multicall
Provides staking, vote power history, vote delegation. The balance received for staking (and thus the voting power) goes up exponentially by the end of the staked period.
State Variables
YEAR_BASE
uint256 public constant YEAR_BASE = 1.5e18;
startTimestamp
This function retrieves the starting timestamp. This may be used for reward calculations or other time-based logic.
uint256 public immutable startTimestamp;
MIN_STAKE_DURATION
uint256 public constant MIN_STAKE_DURATION = 4 weeks;
MAX_STAKE_DURATION
uint256 public constant MAX_STAKE_DURATION = 4 * (365 days);
_lockups
mapping(address => Lockup[]) internal _lockups;
_extenders
mapping(address => mapping(address => mapping(uint256 => bool))) internal _extenders;
baseToken
This function retrieves the address of the ERC20 token used as the base token for staking and rewards.
IERC20 public immutable baseToken;
Functions
constructor
constructor(string memory __name, string memory __symbol) ERC20(__name, __symbol) EIP712(__name, "1");
_stake
Internal function that stakes an amount for a duration to an address.
This function validates that to
is not the zero address and that the duration is within bounds.
Function also does a transferFrom for the base token amount. This requires that the sender approve this ve contract to be able to transfer tokens for the sender.
function _stake(uint128 amount, uint256 duration, address to, uint256 lockupId)
internal
nonReentrant
returns (Lockup memory lockup);
_unstake
Internal function that unstakes an account's lockup.
This function validates that the lockup has not already been claimed and does burn the account's voting votes.
But the function does not transfer the baseTokens to the staker. That transfer operation must be executed seperately as appropiate.
This function also does not validate that the lockup end time has passed nor does it validate that account
has permissions to unstake this lockupId.
function _unstake(address account, uint256 lockupId) internal returns (Lockup memory lockup);
_extend
Internal function that extends an account's lockup.
This function validates that the lockup has not already been claimed.
This function also does not validate that the account
has permissions to unstake this lockupId.
function _extend(address account, uint256 lockupId, uint256 duration, uint128 amount)
internal
returns (Lockup memory newLockup);
stake
This function stakes a specified amount of tokens for a defined duration, allowing the caller (msg.sender) to specify an optional recipient for the staked tokens.
function stake(uint128 amount, uint256 duration, address to) public returns (Lockup memory lockup);
Parameters
amount
uint128
The amount of tokens to be staked.
duration
uint256
The duration of the lockup period.
to
address
The address to which the staked tokens will be credited (optional, defaults to msg.sender).
Returns
lockup
Lockup
A Lockup struct containing details about the newly created lockup (see struct definition for details).
stakeToSender
This function stakes a specified amount of tokens for the caller (msg.sender) for a defined duration.
function stakeToSender(uint128 amount, uint256 duration) public virtual returns (Lockup memory lockup);
Parameters
amount
uint128
The amount of tokens to be staked.
duration
uint256
The duration of the lockup period.
Returns
lockup
Lockup
A Lockup struct containing details about the newly created lockup (see struct definition for details).
unstake
This function unstakes the specified lockup ID for the caller (msg.sender), returning the details of the unstaked lockup.
function unstake(uint256 lockupId, address to) public nonReentrant returns (Lockup memory lockup);
Parameters
lockupId
uint256
The ID of the lockup to be unstaked.
to
address
The address to which the unstaked tokens should be sent (optional, defaults to msg.sender).
Returns
lockup
Lockup
A Lockup struct containing details about the unstaked lockup (see struct definition for details).
unstakeToSender
This function is a simplified version of unstake
that automatically sends the unstaked tokens to the caller (msg.sender).
function unstakeToSender(uint256 lockupId) public returns (Lockup memory lockup);
Parameters
lockupId
uint256
The ID of the lockup to be unstaked.
Returns
lockup
Lockup
A Lockup struct containing details about the unstaked lockup (see struct definition for details).
merge
This function merges multiple lockups associated with the caller (msg.sender) into a single new lockup.
function merge(uint256[] memory lockupIds) public returns (Lockup memory newLockup);
Parameters
lockupIds
uint256[]
An array containing the IDs of the lockups to be merged.
Returns
newLockup
Lockup
A Lockup struct containing details about the newly merged lockup (see struct definition for details).
extendForSender
This function extends the lockup period for the caller (msg.sender) for a specified lockup ID, adding a new duration and amount.
function extendForSender(uint256 lockupId, uint256 duration, uint128 amount)
public
virtual
returns (Lockup memory newLockup);
Parameters
lockupId
uint256
The ID of the lockup to be extended.
duration
uint256
The additional duration to extend the lockup by.
amount
uint128
The additional amount of tokens to be locked.
Returns
newLockup
Lockup
A Lockup struct containing details about the newly extended lockup (see struct definition for details).
extendForAccount
This function extends the lockup period for a specified account, adding a new duration and amount. The caller (msg.sender) must be authorized to manage the lockup through an extender contract.
function extendForAccount(address account, uint256 lockupId, uint256 duration, uint128 amount)
public
returns (Lockup memory newLockup);
Parameters
account
address
The address of the account whose lockup is being extended.
lockupId
uint256
The ID of the lockup to be extended.
duration
uint256
The additional duration to extend the lockup by.
amount
uint128
The additional amount of tokens to be locked.
Returns
newLockup
Lockup
A Lockup struct containing details about the newly extended lockup (see struct definition for details).
approveExtender
This function grants approval for a designated extender contract to manage a specific lockup on behalf of the staker.
function approveExtender(address extender, uint256 lockupId) public;
Parameters
extender
address
The address of the extender contract to be approved.
lockupId
uint256
The ID of the lockup for which to grant approval.
revokeExtender
This function revokes approval previously granted to an extender contract for managing a specific lockup.
function revokeExtender(address extender, uint256 lockupId) public;
Parameters
extender
address
The address of the extender contract whose approval is being revoked.
lockupId
uint256
The ID of the lockup for which to revoke approval.
isApprovedExtender
This function checks whether a specific account has been approved by a staker to manage a particular lockup through an extender contract.
function isApprovedExtender(address account, address extender, uint256 lockupId) public view returns (bool);
Parameters
account
address
The address of the account to check for approval (may be the extender or another account).
extender
address
The address of the extender contract for which to check approval.
lockupId
uint256
The ID of the lockup to verify approval for.
Returns
<none>
bool
isApproved True if the account is approved for the lockup, False otherwise (bool).
_checkApprovedExtender
function _checkApprovedExtender(address account, uint256 lockupId) internal view;
_checkDuration
function _checkDuration(uint256 duration) internal pure;
previewVotes
This function simulates a lockup scenario, providing details about the resulting lockup structure for a specified amount and duration.
function previewVotes(uint128 amount, uint256 duration) public view returns (Lockup memory lockup);
Parameters
amount
uint128
The amount of tokens to be locked.
duration
uint256
The duration of the lockup period.
Returns
lockup
Lockup
A Lockup struct containing details about the simulated lockup (see struct definition for details).
getLockup
This function retrieves the details of a specific lockup for a given staker and lockup index.
function getLockup(address staker, uint256 index) public view returns (Lockup memory lockup);
Parameters
staker
address
The address of the staker for which to retrieve the lockup details.
index
uint256
The index of the lockup within the staker's lockup history.
Returns
lockup
Lockup
A Lockup struct containing details about the lockup (see struct definition for details).
lockupCount
This function retrieves the total number of lockups associated with a specific staker.
function lockupCount(address staker) public view returns (uint256 count);
Parameters
staker
address
The address of the staker for which to retrieve the lockup count.
Returns
count
uint256
The total number of lockups for the staker.
transfer
Transfers of voting balances are not allowed. This function will revert.
function transfer(address, uint256) public pure override returns (bool);
transferFrom
Transfers of voting balances are not allowed. This function will revert.
function transferFrom(address, address, uint256) public pure override returns (bool);
Last updated