This contract is for computing the voting power score of governance token holders (e.g. for an offchain Snapshot vote).
There are three mechanisms through which a token holder can gain voting power with their tokens
- lock up their tokens for a period of time (see ITOKENLOCK)
- stake their tokens directly on this contract
- stake through a staking proxy contract which could offer rewards or yield for staking
For holders with locked tokens a scaling factor serves to reduce or increase the voting power of locked tokens. The scaling factor changes over time, and is looked up based on the current blocktime.
Assumptions: The deployer is responsible for supplying a governance token_ implementing ERC20 and ILOCKER. The deployer is trusted to know & have verified the token code token code is appropriate.
initialize the contract token_ is the token that is staked or locked to get voting power scaling_ is an array of uint8 (bytes) percentage discounts for each epoch epoch_ is the duration of one epoch in seconds
Returns the voting power for who
who indicates the address whose votingPower to compute
returns the voting power for who
Stakes the specified amount
of tokens, this will attempt to transfer the given amount from the caller.
It will count the actual number of tokens trasferred as being staked
MUST emit Staked event.
Returns the number of tokens actually staked
function stakeFor(address voter, address staker, uint256 amount) external override nonReentrant returns (uint256)
Stakes the specified amount
of tokens from staker
on behalf of address voter
,
this will attempt to transfer the given amount from the calling contract.
Must be called from an ISTAKINGPROXY contract that has been approved by staker
.
Tokens will be staked towards the voting power of address voter
allowing one address to delegate voting power to another.
It will count the actual number of tokens trasferred as being staked
MUST trigger Staked event.
Returns the number of tokens actually staked
Unstakes the specified amount
of tokens, this SHOULD return the given amount of tokens to the caller,
MUST trigger Unstaked event.
Unstakes the specified amount
of tokens currently staked by staker
on behalf of voter
,
this SHOULD return the given amount of tokens to the calling contract
calling contract is responsible for returning tokens to staker
if applicable.
MUST trigger Unstaked event.
Returns the current total of tokens staked for address addr
.
Returns the current tokens staked by address staker
for address voter
.
Returns the number of current total tokens staked.
address of the token being used by the staking interface