Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: scroll employee badge #56

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions src/badge/examples/ScrollEmployeeBadge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// 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 {ScrollBadgeDefaultURI} from "../extensions/ScrollBadgeDefaultURI.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 year";

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

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

constructor(
address resolver_,
string memory baseTokenURI_,
string memory defaultBadgeURI_
) ScrollBadge(resolver_) ScrollBadgeDefaultURI(defaultBadgeURI_) {
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(
ScrollBadge,
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 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);

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

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