Hypercerts 是一個用於建立可擴展的回顧性獎勵系統工具以產生正向影響。
IHypercertToken
This interface is the requirements set for hypercert-compliant tokens. This enables developer to use their own preferred token implementation or standard.
HypercertMinter
Example implementation for a hypercert token that is an ERC1155 NFT under the hood with an Allowlist extension.
IHypercertToken
重要的enum去限制轉手行為
enum TransferRestrictions {
AllowAll,
DisallowAll,
FromCreatorOnly
}
及不同的mint方式
HypercertMinter
包含IHypercertToken、SemiFungible1155、AllowlistMinter、PausableUpgradeable
重要的檢查為這個
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual override {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
// By-pass transfer restrictions for minting and burning
if (from == address(0)) {
// Minting
return;
} else if (to == address(0)) {
// Burning
return;
}
// Transfer case, where to and from are non-zero
uint256 len = ids.length;
for (uint256 i; i < len; ) {
uint256 typeID = getBaseType(ids[i]);
TransferRestrictions policy = typeRestrictions[typeID];
if (policy == TransferRestrictions.DisallowAll) {
revert Errors.TransfersNotAllowed();
} else if (policy == TransferRestrictions.FromCreatorOnly && from != creators[typeID]) {
revert Errors.TransfersNotAllowed();
}
unchecked {
++i;
}
}
}