Skip to content

Commit

Permalink
feat: add ScrollEmployeeBadge
Browse files Browse the repository at this point in the history
  • Loading branch information
zimpha committed Sep 9, 2024
1 parent 9cc1a8b commit cb609df
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/badge/examples/ScrollEmployeeBadge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

import {Attestation} from "@eas/contracts/IEAS.sol";

import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

import {ScrollBadge} from "../ScrollBadge.sol";
import {ScrollBadgeAccessControl} from "../extensions/ScrollBadgeAccessControl.sol";
import {ScrollBadgeCustomPayload} from "../extensions/ScrollBadgeCustomPayload.sol";
import {ScrollBadgeNoExpiry} from "../extensions/ScrollBadgeNoExpiry.sol";
import {ScrollBadgeNonRevocable} from "../extensions/ScrollBadgeNonRevocable.sol";
import {ScrollBadgeSingleton} from "../extensions/ScrollBadgeSingleton.sol";

string constant SCROLL_EMPLOYEE_BADGE_SCHEMA = "uint256 employeeId,uint256 year";

function decodePayloadData(bytes memory data) pure returns (uint256,uint256) {
return abi.decode(data, (uint256,uint256));
}

/// @title ScrollEmployeeBadge
contract ScrollEmployeeBadge is
ScrollBadgeAccessControl,
ScrollBadgeCustomPayload,
ScrollBadgeNoExpiry,
ScrollBadgeNonRevocable,
ScrollBadgeSingleton
{
/// @notice The base token URI.
string public baseTokenURI;

constructor(address resolver_, string memory baseTokenURI_) ScrollBadge(resolver_) {
baseTokenURI = baseTokenURI_;
}

/// @notice Update the base token URI.
/// @param baseTokenURI_ The new base token URI.
function updateBaseTokenURI(string memory baseTokenURI_) external onlyOwner {
baseTokenURI = baseTokenURI_;
}

/// @inheritdoc ScrollBadge
function onIssueBadge(Attestation calldata attestation)
internal
override (
ScrollBadgeAccessControl,
ScrollBadgeCustomPayload,
ScrollBadgeNoExpiry,
ScrollBadgeNonRevocable,
ScrollBadgeSingleton
)
returns (bool)
{
return super.onIssueBadge(attestation);
}

/// @inheritdoc ScrollBadge
function onRevokeBadge(Attestation calldata attestation)
internal
override (
ScrollBadge, ScrollBadgeAccessControl, ScrollBadgeCustomPayload, ScrollBadgeNoExpiry, ScrollBadgeSingleton
)
returns (bool)
{
return super.onRevokeBadge(attestation);
}

/// @inheritdoc ScrollBadge
/// @dev This function is TBD
function badgeTokenURI(bytes32 uid) public view override returns (string memory) {
Attestation memory attestation = getAndValidateBadge(uid);
bytes memory payload = getPayload(attestation);
(,uint256 year) = decodePayloadData(payload);

return string(abi.encodePacked(baseTokenURI, Strings.toString(year), ".json"));
}

/// @inheritdoc ScrollBadgeCustomPayload
function getSchema() public pure override returns (string memory) {
return SCROLL_EMPLOYEE_BADGE_SCHEMA;
}
}

0 comments on commit cb609df

Please sign in to comment.