Skip to main content

VotingToken

VotingToken#

Supports snapshotting and allows the Oracle to mint new tokens as rewards.

Functions#

constructor() (public)

Constructs the VotingToken.

decimals() โ†’ uint8 (public)
snapshot() โ†’ uint256 (external)

Creates a new snapshot ID.

_transfer(address from, address to, uint256 value) (internal)
_mint(address account, uint256 value) (internal)
_burn(address account, uint256 value) (internal)
_beforeTokenTransfer(address from, address to, uint256 amount) (internal)
_snapshot() โ†’ uint256 (internal)

Creates a new snapshot and returns its snapshot id. Emits a {Snapshot} event that contains the same id. {_snapshot} is internal and you have to decide how to expose it externally. Its usage may be restricted to a set of accounts, for example using {AccessControl}, or it may be open to the public.

[WARNING]

While an open way of calling {_snapshot} is required for certain trust minimization mechanisms such as forking, you must consider that it can potentially be used by attackers in two ways. First, it can be used to increase the cost of retrieval of values from snapshots, although it will grow logarithmically thus rendering this attack ineffective in the long term. Second, it can be used to target specific accounts and increase the cost of ERC20 transfers for them, in the ways specified in the Gas Costs section above.

We haven't measured the actual numbers; if this is something you're interested in please reach out to us.

_getCurrentSnapshotId() โ†’ uint256 (internal)

Get the current snapshotId

balanceOfAt(address account, uint256 snapshotId) โ†’ uint256 (public)

Retrieves the balance of account at the time snapshotId was created.

totalSupplyAt(uint256 snapshotId) โ†’ uint256 (public)

Retrieves the total supply at the time snapshotId was created.

mint(address recipient, uint256 value) โ†’ bool (external)

Mints value tokens to recipient, returning true on success.

Parameters:#

  • recipient: address to mint to.
  • value: amount of tokens to mint.
burn(uint256 value) (external)

Burns value tokens owned by msg.sender.

Parameters:#

  • value: amount of tokens to burn.
burnFrom(address recipient, uint256 value) โ†’ bool (external)

Burns value tokens owned by recipient.

Parameters:#

  • recipient: address to burn tokens from.
  • value: amount of tokens to burn.
addMinter(address account) (external)

Add Minter role to account.

The caller must have the Owner role.

Parameters:#

  • account: The address to which the Minter role is added.
addBurner(address account) (external)

Add Burner role to account.

The caller must have the Owner role.

Parameters:#

  • account: The address to which the Burner role is added.
resetOwner(address account) (external)

Reset Owner role to account.

The caller must have the Owner role.

Parameters:#

  • account: The new holder of the Owner role.
holdsRole(uint256 roleId, address memberToCheck) โ†’ bool (public)

Whether memberToCheck is a member of roleId.

Reverts if roleId does not correspond to an initialized role.

Parameters:#

  • roleId: the Role to check.
  • memberToCheck: the address to check.
resetMember(uint256 roleId, address newMember) (public)

Changes the exclusive role holder of roleId to newMember.

Reverts if the caller is not a member of the managing role for roleId or if roleId is not an initialized, ExclusiveRole.

Parameters:#

  • roleId: the ExclusiveRole membership to modify.
  • newMember: the new ExclusiveRole member.
getMember(uint256 roleId) โ†’ address (public)

Gets the current holder of the exclusive role, roleId.

Reverts if roleId does not represent an initialized, exclusive role.

Parameters:#

  • roleId: the ExclusiveRole membership to check.
addMember(uint256 roleId, address newMember) (public)

Adds newMember to the shared role, roleId.

Reverts if roleId does not represent an initialized, SharedRole or if the caller is not a member of the managing role for roleId.

Parameters:#

  • roleId: the SharedRole membership to modify.
  • newMember: the new SharedRole member.
removeMember(uint256 roleId, address memberToRemove) (public)

Removes memberToRemove from the shared role, roleId.

Reverts if roleId does not represent an initialized, SharedRole or if the caller is not a member of the managing role for roleId.

Parameters:#

  • roleId: the SharedRole membership to modify.
  • memberToRemove: the current SharedRole member to remove.
renounceMembership(uint256 roleId) (public)

Removes caller from the role, roleId.

Reverts if the caller is not a member of the role for roleId or if roleId is not an initialized, SharedRole.

Parameters:#

  • roleId: the SharedRole membership to modify.
_createSharedRole(uint256 roleId, uint256 managingRoleId, address[] initialMembers) (internal)

Internal method to initialize a shared role, roleId, which will be managed by managingRoleId. initialMembers will be immediately added to the role.

Should be called by derived contracts, usually at construction time. Will revert if the role is already initialized.

_createExclusiveRole(uint256 roleId, uint256 managingRoleId, address initialMember) (internal)

Internal method to initialize an exclusive role, roleId, which will be managed by managingRoleId. initialMember will be immediately added to the role.

Should be called by derived contracts, usually at construction time. Will revert if the role is already initialized.

name() โ†’ string (public)

Returns the name of the token.

symbol() โ†’ string (public)

Returns the symbol of the token, usually a shorter version of the name.

totalSupply() โ†’ uint256 (public)

See {IERC20-totalSupply}.

balanceOf(address account) โ†’ uint256 (public)

See {IERC20-balanceOf}.

transfer(address recipient, uint256 amount) โ†’ bool (public)

See {IERC20-transfer}. Requirements:

  • recipient cannot be the zero address.
  • the caller must have a balance of at least amount.
allowance(address owner, address spender) โ†’ uint256 (public)

See {IERC20-allowance}.

approve(address spender, uint256 amount) โ†’ bool (public)

See {IERC20-approve}. Requirements:

  • spender cannot be the zero address.
transferFrom(address sender, address recipient, uint256 amount) โ†’ bool (public)

See {IERC20-transferFrom}. Emits an {Approval} event indicating the updated allowance. This is not required by the EIP. See the note at the beginning of {ERC20}. Requirements:

  • sender and recipient cannot be the zero address.
  • sender must have a balance of at least amount.
  • the caller must have allowance for sender's tokens of at least amount.
increaseAllowance(address spender, uint256 addedValue) โ†’ bool (public)

Atomically increases the allowance granted to spender by the caller. This is an alternative to {approve} that can be used as a mitigation for problems described in {IERC20-approve}. Emits an {Approval} event indicating the updated allowance. Requirements:

  • spender cannot be the zero address.
decreaseAllowance(address spender, uint256 subtractedValue) โ†’ bool (public)

Atomically decreases the allowance granted to spender by the caller. This is an alternative to {approve} that can be used as a mitigation for problems described in {IERC20-approve}. Emits an {Approval} event indicating the updated allowance. Requirements:

  • spender cannot be the zero address.
  • spender must have allowance for the caller of at least subtractedValue.
_approve(address owner, address spender, uint256 amount) (internal)

Sets amount as the allowance of spender over the owner s tokens. This internal function is equivalent to approve, and can be used to e.g. set automatic allowances for certain subsystems, etc. Emits an {Approval} event. Requirements:

  • owner cannot be the zero address.
  • spender cannot be the zero address.
_afterTokenTransfer(address from, address to, uint256 amount) (internal)

Hook that is called after any transfer of tokens. This includes minting and burning. Calling conditions:

  • when from and to are both non-zero, amount of from's tokens has been transferred to to.
  • when from is zero, amount tokens have been minted for to.
  • when to is zero, amount of from's tokens have been burned.
  • from and to are never both zero. To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
_msgSender() โ†’ address (internal)
_msgData() โ†’ bytes (internal)

Events#

Snapshot(uint256 id)

Emitted by {_snapshot} when a snapshot identified by id is created.

ResetExclusiveMember(uint256 roleId, address newMember, address manager)
AddedSharedMember(uint256 roleId, address newMember, address manager)
RemovedSharedMember(uint256 roleId, address oldMember, address manager)
Transfer(address from, address to, uint256 value)

Emitted when value tokens are moved from one account (from) to another (to). Note that value may be zero.

Approval(address owner, address spender, uint256 value)

Emitted when the allowance of a spender for an owner is set by a call to {approve}. value is the new allowance.

Modifiers#

onlyRoleHolder(uint256 roleId)

Reverts unless the caller is a member of the specified roleId.

onlyRoleManager(uint256 roleId)

Reverts unless the caller is a member of the manager role for the specified roleId.

onlyExclusive(uint256 roleId)

Reverts unless the roleId represents an initialized, exclusive roleId.

onlyShared(uint256 roleId)

Reverts unless the roleId represents an initialized, shared roleId.

onlyValidRole(uint256 roleId)

Reverts if roleId is not initialized.

onlyInvalidRole(uint256 roleId)

Reverts if roleId is initialized.