Follow contracts

Docs checks Tests codecov

Usage

Build

yarn
forge build

Test

forge test

Deploy

forge script script/Deploy.s.sol:Deploy --sig 'deployPowerToken()' \
--chain-id $CHAIN_ID \
--rpc-url $RPC_URL \
--private-key $PRIVATE_KEY \
--verifier-url $VERIFIER_URL \
--verifier $VERIFIER \
--verify \
--broadcast --ffi -vvvv 

# generate easily readable abi to /deployments
forge script script/Deploy.s.sol:Deploy --sig 'sync()' --rpc-url $RPC_URL --broadcast --ffi

Contents

IAchievement

Git Source

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_,
    address powerToken_
) external;

Parameters

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

setAchievement

Only the APP_ADMIN_ROLE can set the achievement details.

function setAchievement(string calldata name, string calldata description, string calldata imageURL)
    external;

Parameters

NameTypeDescription
namestringName of the achievement.
descriptionstringDescription of the achievement.
imageURLstringImage URL of the achievement.

mint

Mints a token to account.

function mint(string calldata achievement) external returns (uint256 tokenId);

Parameters

NameTypeDescription
achievementstringName of the achievement to mint.

Returns

NameTypeDescription
tokenIduint256The new minted token id.

totalSupply

Returns total supply of tokens.

function totalSupply() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256Total supply of tokens.

getAllAchievements

Returns the achievement details of all achievements.

function getAllAchievements() external view returns (AchievementDetails[] memory);

Returns

NameTypeDescription
<none>AchievementDetails[]Achievement details.

hasAchievement

Returns whether the account has the achievement.

function hasAchievement(address account, string calldata achievementName)
    external
    view
    returns (bool);

Parameters

NameTypeDescription
accountaddressThe address of the account.
achievementNamestringThe name of the achievement.

Returns

NameTypeDescription
<none>boolWhether the account has the achievement.

powerToken

Returns the address of the PowerToken contract.

function powerToken() external view returns (address);

Returns

NameTypeDescription
<none>addressAddress of the PowerToken contract.

IErrors

Git Source

Errors

Unauthorized

receiver is empty.

error Unauthorized();

AchievementNotSet

achievement is not set.

error AchievementNotSet();

AlreadyMinted

achievement is already mint.

error AlreadyMinted(string achievementName);

IEvents

Git Source

Events

AchievementSet

event AchievementSet(string indexed name, string description, string imageURL);

IErrors

Git Source

Errors

ReceiverIsEmpty

receiver is empty.

error ReceiverIsEmpty();

PointsInvalidReceiver

Points receiver is invalid.

error PointsInvalidReceiver(bytes32);

AmountIsZero

Amount is zero.

error AmountIsZero();

InsufficientBalanceAndPoints

Insufficient balance and points.

error InsufficientBalanceAndPoints();

InsufficientBalanceToTransfer

Insufficient balance to transfer.

error InsufficientBalanceToTransfer();

ExceedsMaxSupply

Exceeds max supply.

error ExceedsMaxSupply();

AlreadyMintedToday

Already minted today.

error AlreadyMintedToday(address account);

ExceedsDailyLimit

Exceeds daily limit.

error ExceedsDailyLimit();

IEvents

Git Source

Events

DistributePoints

Emitted when points are distributed to an address.

event DistributePoints(address indexed to, uint256 indexed amount);

Tip

Emitted when points are tipped from one address to another.

event Tip(address indexed from, address indexed to, bytes32 indexed feedId, uint256 amount);

Purchase

Emitted when points are paid from one address to another for some purchase.

event Purchase(address indexed from, address indexed to, bytes32 indexed feedId, uint256 amount);

AirdropTokens

Emitted when points are airdropped to an address.

event AirdropTokens(address indexed to, uint256 indexed amount);

TaxCollected

Emitted when tax is collected.

event TaxCollected(address indexed collector, uint256 indexed amount);

Parameters

NameTypeDescription
collectoraddressThe address that collected the tax.
amountuint256The amount of tax collected.

WithdrawnByFeedId

Emitted when points are withdrawn by feed id.

event WithdrawnByFeedId(address indexed to, bytes32 indexed feedId, uint256 indexed amount);

Withdrawn

Emitted when tokens are withdrawn from an address.

event Withdrawn(address indexed user, address indexed to, uint256 indexed amount);

IPowerToken

Git Source

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_,
    uint256 dailyMintLimit_
) external;

Parameters

NameTypeDescription
name_stringThe name of the token.
symbol_stringThe symbol of the token.
admin_addressThe account to be granted with APP_ADMIN_ROLE.
dailyMintLimit_uint256The 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;

Parameters

NameTypeDescription
limituint256The 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;

Parameters

NameTypeDescription
treasuryAdminaddressThe account to receive the tokens.
amountuint256The 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;

Parameters

NameTypeDescription
toaddressThe account to receive the token points.
amountuint256The amount of token points to mint.
taxBasisPointsuint256The 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;

Parameters

NameTypeDescription
amountuint256The amount of token points to mint.
taxBasisPointsuint256The 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;

Parameters

NameTypeDescription
toaddressThe account to receive the tokens.
amountuint256The amount of tokens to mint.
taxBasisPointsuint256The 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;

Parameters

NameTypeDescription
amountuint256The amount of token points to send.
toaddressThe address to send the token points. It can be empty.
feedIdbytes32The feed id. It can be empty.
taxBasisPointsuint256The 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;

Parameters

NameTypeDescription
amountuint256The amount of token points to send.
toaddressThe address to send the token points. It can be empty.
feedIdbytes32The feed id. It can be empty.
taxBasisPointsuint256The 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;

Parameters

NameTypeDescription
toaddressThe address who receives the tokens.
feedIdbytes32The 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;

Parameters

NameTypeDescription
accountaddressThe 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;

Parameters

NameTypeDescription
accountsaddress[]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;

Parameters

NameTypeDescription
accountaddressThe address from which to revoke the role.

balanceOfByFeed

Return the balance of the feedId

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

Parameters

NameTypeDescription
feedIdbytes32The feed id

Returns

NameTypeDescription
<none>uint256The amount of the balance

balanceOfPoints

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

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

Parameters

NameTypeDescription
owneraddressThe address of the owner

Returns

NameTypeDescription
<none>uint256The amount of the balance

getDailyMintLimit

Returns the token limit for daily mint.

function getDailyMintLimit() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256The token limit for daily mint.

Contents

AchievementDetails

Git Source

struct AchievementDetails {
    string name;
    string description;
    string imageURL;
}

Contents

Achievement

Git Source

Inherits: IERC721, AccessControlEnumerableUpgradeable, ERC721Upgradeable, IErrors, IEvents, IAchievement

State Variables

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");

_counter

uint256 internal _counter;

_totalSupply

uint256 internal _totalSupply;

_powerToken

address internal _powerToken;

_achievements

EnumerableSet.Bytes32Set internal _achievements;

_achievementDetails

mapping(bytes32 => AchievementDetails) internal _achievementDetails;

_tokenIdToAchievements

mapping(uint256 => bytes32) internal _tokenIdToAchievements;

_userAchievements

mapping(address => mapping(bytes32 => bool)) internal _userAchievements;

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_,
    address powerToken_
) external override initializer;

Parameters

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

setAchievement

Only the APP_ADMIN_ROLE can set the achievement details.

function setAchievement(string calldata name, string calldata description, string calldata imageURL)
    external
    override
    onlyRole(APP_ADMIN_ROLE);

Parameters

NameTypeDescription
namestringName of the achievement.
descriptionstringDescription of the achievement.
imageURLstringImage URL of the achievement.

mint

Mints a token to account.

function mint(string calldata achievementName) external override returns (uint256 tokenId);

Parameters

NameTypeDescription
achievementNamestring

Returns

NameTypeDescription
tokenIduint256The new minted token id.

tokenURI

See {IERC721Metadata-tokenURI}.

function tokenURI(uint256 id) public view override returns (string memory);

totalSupply

Returns total supply of tokens.

function totalSupply() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256Total supply of tokens.

getAllAchievements

Returns the achievement details of all achievements.

function getAllAchievements() external view override returns (AchievementDetails[] memory);

Returns

NameTypeDescription
<none>AchievementDetails[]Achievement details.

hasAchievement

Returns whether the account has the achievement.

function hasAchievement(address account, string calldata achievementName)
    external
    view
    override
    returns (bool);

Parameters

NameTypeDescription
accountaddressThe address of the account.
achievementNamestringThe name of the achievement.

Returns

NameTypeDescription
<none>boolWhether the account has the achievement.

powerToken

Returns the address of the PowerToken contract.

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

Returns

NameTypeDescription
<none>addressAddress of the PowerToken contract.

supportsInterface

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(AccessControlEnumerableUpgradeable, ERC721Upgradeable, IERC165)
    returns (bool);

_getNameHash

function _getNameHash(string calldata name) internal pure returns (bytes32);

Contents

TransparentUpgradeableProxy

Git Source

Inherits: ERC1967Proxy

*This contract implements a proxy that is upgradeable by an admin. To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector clashing], which can potentially be used in an attack, this contract uses the https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two things that go hand in hand:

  1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if that call matches one of the admin functions exposed by the proxy itself.
  2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the implementation. If the admin tries to call a function on the implementation it will fail with an error that says "admin cannot fallback to proxy target". These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due to sudden errors when trying to call a function from the proxy implementation. Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way, you should think of the ProxyAdmin instance as the real administrative interface of your proxy.*

Functions

constructor

Initializes an upgradeable proxy managed by _admin, backed by the implementation at _logic, and optionally initialized with _data as explained in ERC1967Proxy-constructor.

constructor(address _logic, address admin_, bytes memory _data)
    payable
    ERC1967Proxy(_logic, _data);

ifAdmin

Modifier used internally that will delegate the call to the implementation unless the sender is the admin.

modifier ifAdmin();

admin

Returns the current admin. NOTE: Only the admin can call this function. See ProxyAdmin-getProxyAdmin. TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the https://eth.wiki/json-rpc/API#eth_getstorageat[eth_getStorageAt] RPC call. 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103

function admin() external ifAdmin returns (address admin_);

implementation

Returns the current implementation. NOTE: Only the admin can call this function. See ProxyAdmin-getProxyImplementation. TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the https://eth.wiki/json-rpc/API#eth_getstorageat[eth_getStorageAt] RPC call. 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc

function implementation() external ifAdmin returns (address implementation_);

changeAdmin

Changes the admin of the proxy. Emits an {AdminChanged} event. NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.

function changeAdmin(address newAdmin) external virtual ifAdmin;

upgradeTo

Upgrade the implementation of the proxy. NOTE: Only the admin can call this function. See ProxyAdmin-upgrade.

function upgradeTo(address newImplementation) external ifAdmin;

upgradeToAndCall

Upgrade the implementation of the proxy, and then call a function from the new implementation as specified by data, which should be an encoded function call. This is useful to initialize new storage variables in the proxied contract. NOTE: Only the admin can call this function. See ProxyAdmin-upgradeAndCall.

function upgradeToAndCall(address newImplementation, bytes calldata data)
    external
    payable
    ifAdmin;

_admin

Returns the current admin.

function _admin() internal view virtual returns (address);

_beforeFallback

Makes sure the admin cannot access the fallback function. See Proxy-_beforeFallback.

function _beforeFallback() internal virtual override;

PowerToken

Git Source

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

NameTypeDescription
name_stringThe name of the token.
symbol_stringThe symbol of the token.
admin_addressThe account to be granted with APP_ADMIN_ROLE.
dailyMintLimit_uint256The 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

NameTypeDescription
limituint256The 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

NameTypeDescription
treasuryAdminaddressThe account to receive the tokens.
amountuint256The 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

NameTypeDescription
toaddressThe account to receive the token points.
amountuint256The amount of token points to mint.
taxBasisPointsuint256The 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

NameTypeDescription
amountuint256The amount of token points to mint.
taxBasisPointsuint256The 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

NameTypeDescription
toaddressThe account to receive the tokens.
amountuint256The amount of tokens to mint.
taxBasisPointsuint256The 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

NameTypeDescription
amountuint256The amount of token points to send.
toaddressThe address to send the token points. It can be empty.
feedIdbytes32The feed id. It can be empty.
taxBasisPointsuint256The 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

NameTypeDescription
amountuint256The amount of token points to send.
toaddressThe address to send the token points. It can be empty.
feedIdbytes32The feed id. It can be empty.
taxBasisPointsuint256The 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

NameTypeDescription
toaddressThe address who receives the tokens.
feedIdbytes32The 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

NameTypeDescription
accountaddressThe 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

NameTypeDescription
accountsaddress[]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

NameTypeDescription
accountaddressThe 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

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

getDailyMintLimit

Returns the token limit for daily mint.

function getDailyMintLimit() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256The 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

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

_getTaxAmount

function _getTaxAmount(uint256 taxBasisPoints, uint256 amount) internal pure returns (uint256);