Valocracy

Git Source

Inherits: ERC20Votes, Ownable, SDG

Implementation of the EIP-7787 Soulbound Degradable Governance standard using ERC20 tokens

This contract extends ERC20Votes to implement non-transferable tokens with decaying voting power

State Variables

SECONDS_PER_DAY

Number of seconds in a day

uint32 private constant SECONDS_PER_DAY = 86400;

_lastParticipation

Mapping from accounts addresses to their last participation timestamp

mapping(address => uint32) private _lastParticipation;

Functions

constructor

Initializes the contract by setting a name and a symbol. Sets default stable and decay periods to 90 days each.

constructor(string memory name, string memory symbol)
    ERC20(name, symbol)
    ERC20Votes()
    Ownable(msg.sender)
    EIP712(name, "1");

Parameters

NameTypeDescription
namestringThe name of the token
symbolstringThe symbol of the token

tokenURI

Returns the token URI for a given token ID.

function tokenURI(uint256 tokenId) public view returns (string memory);

Parameters

NameTypeDescription
tokenIduint256The ID of the token

Returns

NameTypeDescription
<none>stringThe token URI

_update

Overrides the ERC20Votes-_update to make the token soulbound. Only allows minting and burning, prevents transfers between accounts.

function _update(address from, address to, uint256 value) internal virtual override;

Parameters

NameTypeDescription
fromaddressThe address sending the tokens
toaddressThe address receiving the tokens
valueuint256The amount of tokens

balanceOf

*Returns the balance of account with decay applied. Implements the EIP-7787 decay mechanism:

  • Full balance during stable period
  • Linear decay during decay period
  • Zero balance after decay period ends*
function balanceOf(address account) public view override(ERC20, SDG) returns (uint256);

Parameters

NameTypeDescription
accountaddressThe address to check the balance for

Returns

NameTypeDescription
<none>uint256The current balance with decay applied

_getVotingUnits

Returns the voting units for an account.

function _getVotingUnits(address account) internal view override returns (uint256);

Parameters

NameTypeDescription
accountaddressThe address to check voting units for

Returns

NameTypeDescription
<none>uint256The current voting units

grantVotingUnits

Grants voting units to the specified account by amount. Only the contract owner can mint new tokens and grant additional voting units. Updates the last participation timestamp to start the stable period.

function grantVotingUnits(address to, uint256 amount) public onlyOwner;

Parameters

NameTypeDescription
toaddressThe address to grant voting units to
amountuint256The amount of voting units to grant

burn

Burns tokens and reduces the voting units associated with the token holder.

function burn(uint256 amount) public virtual;

Parameters

NameTypeDescription
amountuint256The amount of tokens to burn