Git Source

Inherits: ERC20, ERC20Burnable, AccessControl, IProtocolToken, IZeroAddressError, ReentrancyGuard, ITokenEvents, IApplicationEvents

Author: @ShaneDuncan602, @oscarsernarosero, @TJ-Everett, @Palmerg4

This is an example implementation that App Devs should use.

During deployment _tokenName _tokenSymbol _tokenAdmin are set in constructor

State Variables

TOKEN_ADMIN_ROLE

bytes32 constant TOKEN_ADMIN_ROLE = keccak256("TOKEN_ADMIN_ROLE");

handlerAddress

address private handlerAddress;

Functions

constructor

Constructor sets params

constructor(string memory _name, string memory _symbol, address _tokenAdmin) ERC20(_name, _symbol);

Parameters

NameTypeDescription
_namestringName of the token
_symbolstringSymbol of the token
_tokenAdminaddressToken Admin address

mint

Function mints new tokens.

function mint(address to, uint256 amount) public virtual;

Parameters

NameTypeDescription
toaddressrecipient address
amountuint256number of tokens to mint

transfer

TRANSFER FUNCTION GROUP START

*This is overridden from IERC20-transfer. It handles all fees/discounts and then uses ERC20 _transfer to do the actual transfers Requirements:

  • to cannot be the zero address.
  • the caller must have a balance of at least amount.*
function transfer(address to, uint256 amount) public virtual override nonReentrant returns (bool);

transferFrom

*This is overridden from IERC20-transferFrom. It handles all fees/discounts and then uses ERC20 _transfer to do the actual transfers Emits an event indicating the updated allowance. This is not required by the EIP. See the note at the beginning of . NOTE: Does not update the allowance if the current allowance is the maximum uint256. Requirements:

  • from and to cannot be the zero address.
  • from must have a balance of at least amount.
  • the caller must have allowance for from’s tokens of at least amount.*
function transferFrom(address from, address to, uint256 amount) public override nonReentrant returns (bool);

_handleFees

This transfers all the P2P transfer fees to the individual fee sinks

function _handleFees(address from, uint256 amount) internal returns (uint256);

Parameters

NameTypeDescription
fromaddresssender address
amountuint256number of tokens being transferred

_beforeTokenTransfer

TRANSFER FUNCTION GROUP END

Function called before any token transfers to confirm transfer is within rules of the protocol

function _beforeTokenTransfer(address from, address to, uint256 amount) internal override;

Parameters

NameTypeDescription
fromaddresssender address
toaddressrecipient address
amountuint256number of tokens to be transferred

getHandlerAddress

Rule Processor Module Check

This function returns the handler address

function getHandlerAddress() external view override returns (address);

Returns

NameTypeDescription
<none>addresshandlerAddress

connectHandlerToToken

This function does not check for zero address. Zero address is a valid address for this function’s purpose.

Function to connect Token to previously deployed Handler contract

function connectHandlerToToken(address _deployedHandlerAddress) external override onlyRole(TOKEN_ADMIN_ROLE);

Parameters

NameTypeDescription
_deployedHandlerAddressaddressaddress of the currently deployed Handler Address