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