From 1eeab4ea1f85a4da1e61c013deaeeaf72a80dabe Mon Sep 17 00:00:00 2001 From: zimpha Date: Fri, 22 Nov 2024 16:18:48 +0800 Subject: [PATCH] naming and missing override --- src/Common.sol | 2 +- src/badge/examples/SCRHoldingBadge.sol | 50 ++++++++++++------- .../extensions/ScrollBadgeDefaultURI.sol | 2 +- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/Common.sol b/src/Common.sol index fe5233c..19f8238 100644 --- a/src/Common.sol +++ b/src/Common.sol @@ -12,4 +12,4 @@ function decodeBadgeData(bytes memory data) pure returns (address, bytes memory) function encodeBadgeData(address badge, bytes memory payload) pure returns (bytes memory) { return abi.encode(badge, payload); -} \ No newline at end of file +} diff --git a/src/badge/examples/SCRHoldingBadge.sol b/src/badge/examples/SCRHoldingBadge.sol index 9fe04a0..fc6c4e3 100644 --- a/src/badge/examples/SCRHoldingBadge.sol +++ b/src/badge/examples/SCRHoldingBadge.sol @@ -28,17 +28,16 @@ contract SCRHoldingBadge is ScrollBadgeCustomPayload, ScrollBadgeDefaultURI, Own uint256 private constant LEVEL_TWO_SCR_AMOUNT = 10 ether; uint256 private constant LEVEL_THREE_SCR_AMOUNT = 100 ether; uint256 private constant LEVEL_FOUR_SCR_AMOUNT = 1000 ether; - uint256 private constant LEVEL_FIVE_SCR_AMOUNT = 10000 ether; - uint256 private constant LEVEL_SIX_SCR_AMOUNT = 100000 ether; + uint256 private constant LEVEL_FIVE_SCR_AMOUNT = 10_000 ether; + uint256 private constant LEVEL_SIX_SCR_AMOUNT = 100_000 ether; /// @notice The address of SCR token. address public immutable scr; - constructor( - address resolver_, - string memory baseTokenURI_, - address scr_ - ) ScrollBadge(resolver_) ScrollBadgeDefaultURI(baseTokenURI_) { + constructor(address resolver_, string memory baseTokenURI_, address scr_) + ScrollBadge(resolver_) + ScrollBadgeDefaultURI(baseTokenURI_) + { scr = scr_; } @@ -49,33 +48,48 @@ contract SCRHoldingBadge is ScrollBadgeCustomPayload, ScrollBadgeDefaultURI, Own } /// @inheritdoc ScrollBadge - function onIssueBadge( - Attestation calldata - ) internal virtual override(ScrollBadge, ScrollBadgeCustomPayload) returns (bool) { + function onIssueBadge(Attestation calldata) + internal + virtual + override (ScrollBadge, ScrollBadgeCustomPayload) + returns (bool) + { return false; } /// @inheritdoc ScrollBadge - function onRevokeBadge( - Attestation calldata - ) internal virtual override(ScrollBadge, ScrollBadgeCustomPayload) returns (bool) { + function onRevokeBadge(Attestation calldata) + internal + virtual + override (ScrollBadge, ScrollBadgeCustomPayload) + returns (bool) + { return false; } /// @inheritdoc ScrollBadge - function badgeTokenURI( - bytes32 uid - ) public view override(IScrollBadge, ScrollBadge, ScrollBadgeDefaultURI) returns (string memory) { + function badgeTokenURI(bytes32 uid) + public + view + override (IScrollBadge, ScrollBadge, ScrollBadgeDefaultURI) + returns (string memory) + { return ScrollBadgeDefaultURI.badgeTokenURI(uid); } + /// @inheritdoc IScrollBadge + function hasBadge(address user) public view virtual override (IScrollBadge, ScrollBadge) returns (bool) { + uint256 balance = IERC20(scr).balanceOf(user); + return balance >= LEVEL_ONE_SCR_AMOUNT; + } + /// @inheritdoc ScrollBadgeDefaultURI function getBadgeTokenURI(bytes32 uid) internal view override returns (string memory) { Attestation memory attestation = getAndValidateBadge(uid); bytes memory payload = getPayload(attestation); - uint256 year = decodePayloadData(payload); + uint256 level = decodePayloadData(payload); - return string(abi.encodePacked(defaultBadgeURI, Strings.toString(year), ".json")); + return string(abi.encodePacked(defaultBadgeURI, Strings.toString(level), ".json")); } /// @inheritdoc ScrollBadgeCustomPayload diff --git a/src/badge/extensions/ScrollBadgeDefaultURI.sol b/src/badge/extensions/ScrollBadgeDefaultURI.sol index 1bcf29d..41a4ec8 100644 --- a/src/badge/extensions/ScrollBadgeDefaultURI.sol +++ b/src/badge/extensions/ScrollBadgeDefaultURI.sol @@ -14,7 +14,7 @@ abstract contract ScrollBadgeDefaultURI is ScrollBadge { } /// @inheritdoc ScrollBadge - function badgeTokenURI(bytes32 uid) public view override virtual returns (string memory) { + function badgeTokenURI(bytes32 uid) public view virtual override returns (string memory) { if (uid == bytes32(0)) { return defaultBadgeURI; }