PowerToken

Git Source

Inherits: IPowerToken, IErrors, IEvents, AccessControlEnumerableUpgradeable, ERC20Upgradeable

State Variables

version

string public constant version = "1.0.0";

APP_ADMIN_ROLE

bytes32 public constant APP_ADMIN_ROLE = keccak256("APP_ADMIN_ROLE");

MAX_SUPPLY

uint256 public constant MAX_SUPPLY = 10_000_000_000 ether;

_pointsBalancesV1

mapping(address account => uint256) internal _pointsBalancesV1;

_feedBalances

Token balances of the feed, which could be withdrawn to the feed owner.

mapping(bytes32 feedId => uint256) internal _feedBalances;

_pointsBalancesV2

Points balances of the users, which are non-transferable and can be used to tip others. Points balances are included in user's balance.

mapping(address account => uint256) internal _pointsBalancesV2;

Functions

initialize

Initializes the contract. Setup token name, symbol and account with APP_ADMIN_ROLE.

function initialize(string calldata name_, string calldata symbol_, address admin_)
    external
    override
    reinitializer(3);

Parameters

NameTypeDescription
name_stringThe name of the token.
symbol_stringThe symbol of the token.
admin_addressThe account to be granted with APP_ADMIN_ROLE.

migrate

Migrates the token points of users.

The caller must have the APP_ADMIN_ROLE.

function migrate(address[] calldata users, bytes32[] calldata feedIds)
    external
    override
    onlyRole(APP_ADMIN_ROLE);

Parameters

NameTypeDescription
usersaddress[]The addresses of the users to migrate.
feedIdsbytes32[]The feed ids of the feeds to migrate.

mint

Mints new token points.

The caller must have the APP_ADMIN_ROLE.

function mint(address to, uint256 amount) external override onlyRole(APP_ADMIN_ROLE);

Parameters

NameTypeDescription
toaddressThe account to receive the token points.
amountuint256The amount of token points to mint.

tip

Tips with token points. If token points are not enough, it will try the balance.

The to and feedId are optional, but at least one of them must be provided. If both are provided, the to will be used.

function tip(uint256 amount, address to, bytes32 feedId) external override;

Parameters

NameTypeDescription
amountuint256The amount of token points to send. It can be empty.
toaddressThe address to send the token points. It can be empty.
feedIdbytes32The feed id. It can be empty.

withdrawByFeedId

Withdraws tokens by feedId. to is supposed to be the true owner of the feedId.

The caller must have the APP_ADMIN_ROLE.

function withdrawByFeedId(address to, bytes32 feedId) external override onlyRole(APP_ADMIN_ROLE);

Parameters

NameTypeDescription
toaddressThe address who receives the tokens.
feedIdbytes32The amount belongs to the feedId.

balanceOfPoints

Return the balance of points, aka the inactive tokens, of the owner

function balanceOfPoints(address owner) external view override returns (uint256);

Parameters

NameTypeDescription
owneraddressThe address of the owner

Returns

NameTypeDescription
<none>uint256The amount of the balance

balanceOfByFeed

Return the balance of the feedId

function balanceOfByFeed(bytes32 feedId) external view override returns (uint256);

Parameters

NameTypeDescription
feedIdbytes32The feed id

Returns

NameTypeDescription
<none>uint256The amount of the balance

transfer

Moves amount tokens from the caller's account to to.

function transfer(address to, uint256 value) public override returns (bool);

transferFrom

Moves amount tokens from from to to using the allowance mechanism. amount is then deducted from the caller's allowance.

function transferFrom(address from, address to, uint256 value) public override returns (bool);

_mintPoints

Mints points to a specified address. Increases the points balance of the recipient and mints the corresponding amount of tokens. Reverts if the total supply exceeds the maximum supply.

function _mintPoints(address to, uint256 amount) internal;

_checkTransferBalance

Checks if the transfer balance is sufficient. This function verifies that the from address has enough balance to cover the transfer amount after accounting for the points balance.

function _checkTransferBalance(address from, uint256 value) internal view;

Parameters

NameTypeDescription
fromaddressThe address from which the tokens are being transferred.
valueuint256The amount of tokens to be transferred.