PowerToken
Inherits: IPowerToken, IErrors, IEvents, AccessControlEnumerableUpgradeable, ERC20Upgradeable
State Variables
version
string public constant version = "1.1.0";
APP_ADMIN_ROLE
bytes32 public constant APP_ADMIN_ROLE = keccak256("APP_ADMIN_ROLE");
APP_USER_ROLE
bytes32 public constant APP_USER_ROLE = keccak256("APP_USER_ROLE");
MAX_SUPPLY
uint256 public constant MAX_SUPPLY = 10_000_000_000 ether;
ADMIN
address public immutable ADMIN;
_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;
_dailyMinted
mapping(address account => mapping(uint256 day => bool hasMinted)) internal _dailyMinted;
_dailyMintLimit
uint256 internal _dailyMintLimit;
Functions
onlyAdminRole
modifier onlyAdminRole();
constructor
constructor(address admin_);
initialize
Initializes the contract. Setup token name, symbol and account with APP_ADMIN_ROLE.
function initialize(
string calldata name_,
string calldata symbol_,
address admin_,
uint256 dailyMintLimit_
) external override reinitializer(4);
Parameters
Name | Type | Description |
---|---|---|
name_ | string | The name of the token. |
symbol_ | string | The symbol of the token. |
admin_ | address | The account to be granted with APP_ADMIN_ROLE. |
dailyMintLimit_ | uint256 | The token limit for daily mint. |
setDailyMintLimit
Sets the token limit for daily mint.
The caller must have the APP_ADMIN_ROLE.
function setDailyMintLimit(uint256 limit) external override onlyAdminRole;
Parameters
Name | Type | Description |
---|---|---|
limit | uint256 | The new limit to set. |
mintToTreasury
Mints tokens to the treasury.
The caller must have the APP_ADMIN_ROLE.
function mintToTreasury(address treasuryAdmin, uint256 amount) external override onlyAdminRole;
Parameters
Name | Type | Description |
---|---|---|
treasuryAdmin | address | The account to receive the tokens. |
amount | uint256 | The amount of tokens to mint. |
mint
Issues new token points.
The caller must have the APP_ADMIN_ROLE.
function mint(address to, uint256 amount, uint256 taxBasisPoints) external override onlyAdminRole;
Parameters
Name | Type | Description |
---|---|---|
to | address | The account to receive the token points. |
amount | uint256 | The amount of token points to mint. |
taxBasisPoints | uint256 | The tax basis points. |
dailyMint
Issues new token points to caller.
The caller must have the APP_USER_ROLE.
function dailyMint(uint256 amount, uint256 taxBasisPoints)
external
override
onlyRole(APP_USER_ROLE);
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | The amount of token points to mint. |
taxBasisPoints | uint256 | The tax basis points. |
airdrop
Airdrops tokens to the users.
The caller must have the APP_ADMIN_ROLE.
function airdrop(address to, uint256 amount, uint256 taxBasisPoints)
external
override
onlyAdminRole;
Parameters
Name | Type | Description |
---|---|---|
to | address | The account to receive the tokens. |
amount | uint256 | The amount of tokens to mint. |
taxBasisPoints | uint256 | The tax basis points. |
purchase
Purchases 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 purchase(uint256 amount, address to, bytes32 feedId, uint256 taxBasisPoints)
external
override;
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | The amount of token points to send. |
to | address | The address to send the token points. It can be empty. |
feedId | bytes32 | The feed id. It can be empty. |
taxBasisPoints | uint256 | The tax basis points. |
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, uint256 taxBasisPoints)
external
override;
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | The amount of token points to send. |
to | address | The address to send the token points. It can be empty. |
feedId | bytes32 | The feed id. It can be empty. |
taxBasisPoints | uint256 | The tax basis points. |
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 onlyAdminRole;
Parameters
Name | Type | Description |
---|---|---|
to | address | The address who receives the tokens. |
feedId | bytes32 | The amount belongs to the feedId. |
addUser
Grants the APP_USER_ROLE to the specified account and send native tokens to it.
The caller must have the APP_ADMIN_ROLE.
function addUser(address account) external payable override onlyAdminRole;
Parameters
Name | Type | Description |
---|---|---|
account | address | The address to grant the role. |
addUsers
Grants the APP_USER_ROLE to the specified accounts.
The caller must have the APP_ADMIN_ROLE.
function addUsers(address[] calldata accounts) external payable override onlyAdminRole;
Parameters
Name | Type | Description |
---|---|---|
accounts | address[] | The addresses to grant the role. |
removeUser
Revokes the APP_USER_ROLE from the specified account.
The caller must have the APP_ADMIN_ROLE.
function removeUser(address account) external override onlyAdminRole;
Parameters
Name | Type | Description |
---|---|---|
account | address | The address from which to revoke the role. |
balanceOfPoints
Return the balance of points, aka the inactive tokens, of the owner
function balanceOfPoints(address owner) external view override returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
owner | address | The address of the owner |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount of the balance |
balanceOfByFeed
Return the balance of the feedId
function balanceOfByFeed(bytes32 feedId) external view override returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
feedId | bytes32 | The feed id |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount of the balance |
getDailyMintLimit
Returns the token limit for daily mint.
function getDailyMintLimit() external view override returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The token limit for daily mint. |
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);
_payWithTax
function _payWithTax(
address from,
address to,
bytes32 feedId,
uint256 amount,
uint256 taxBasisPoints
) internal returns (uint256);
_issuePoints
Issues points to a specified address by transferring tokens from the token contract.
function _issuePoints(address to, uint256 amount, uint256 taxBasisPoints) internal;
_setMinted
function _setMinted(address account, uint256 day) internal;
_hasMinted
function _hasMinted(address account, uint256 day) internal view returns (bool);
_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
Name | Type | Description |
---|---|---|
from | address | The address from which the tokens are being transferred. |
value | uint256 | The amount of tokens to be transferred. |
_getTaxAmount
function _getTaxAmount(uint256 taxBasisPoints, uint256 amount) internal pure returns (uint256);