Git Source

Inherits: ERC20, ERC20Burnable, ReentrancyGuard, [RulesEngineClientERC20](/v2(/v2/reference/client/RulesEngineClientERC20.sol/abstract.RulesEngineClientERC20)

Author: @mpetersoCode55, @ShaneDuncan602, @TJ-Everett, @VoR0220

This contract demonstrates how to integrate the Rules Engine with an ERC20 token for policy enforcement.

This contract is an example implementation of an ERC20 token integrated with the Rules Engine. It extends the OpenZeppelin ERC20 and ERC20Burnable contracts and includes additional functionality for interacting with the Rules Engine. The contract ensures compliance with policies defined in the Rules Engine for minting, transferring, and transferring tokens on behalf of others.

Functions

constructor

Constructor for the Example ERC20 token.

Initializes the token with a name and symbol.

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

Parameters

NameTypeDescription
_namestringThe name of the token.
_symbolstringThe symbol of the token.

mint

Mints new tokens to a specified address.

This function interacts with the Rules Engine to ensure compliance with minting policies.

function mint(address to, uint256 amount)
    public
    virtual
    checksPoliciesERC20MintBefore(to, amount, balanceOf(msg.sender), balanceOf(to), block.timestamp);

Parameters

NameTypeDescription
toaddressThe recipient address.
amountuint256The number of tokens to mint.

transfer

Transfers tokens to a specified address.

This function overrides the [IERC20-transfer](/v2(/v2/reference/example/ExampleUserContract.sol/contract.ExampleUserContract.md#transfer) function and interacts with the Rules Engine to ensure compliance with transfer policies. It includes a reentrancy guard to prevent reentrancy attacks.

function transfer(address to, uint256 amount)
    public
    virtual
    override
    nonReentrant
    checksPoliciesERC20TransferBefore(to, amount, balanceOf(msg.sender), balanceOf(to), block.timestamp)
    returns (bool);

Parameters

NameTypeDescription
toaddressThe recipient address.
amountuint256The number of tokens to transfer.

Returns

NameTypeDescription
<none>boolbool True if the transfer is successful, false otherwise.

transferFrom

Transfers tokens on behalf of another address.

This function overrides the IERC20-transferFrom function and interacts with the Rules Engine to ensure compliance with transfer policies. It includes a reentrancy guard to prevent reentrancy attacks.

function transferFrom(address from, address to, uint256 amount)
    public
    virtual
    override
    nonReentrant
    checksPoliciesERC20TransferFromBefore(from, to, amount, balanceOf(msg.sender), balanceOf(to), block.timestamp)
    returns (bool);

Parameters

NameTypeDescription
fromaddressThe address to transfer tokens from.
toaddressThe recipient address.
amountuint256The number of tokens to transfer.

Returns

NameTypeDescription
<none>boolbool True if the transfer is successful, false otherwise.