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: implement default token uri #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
22 changes: 15 additions & 7 deletions script/DeployPassportDevZKBadge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.19;

import "forge-std/Script.sol";
import {Base64} from "@openzeppelin/contracts/utils/Base64.sol";
import {PassportDevZKBadge} from "../src/PassportDevZKBadge.sol";

contract DeployPassportDevZKBadge is Script {
Expand Down Expand Up @@ -42,14 +43,21 @@ contract DeployPassportDevZKBadge is Script {
rollupDescriptions[3] = "Contributed to ZK rollups projects";

string[] memory rollupImageUris = new string[](4);
rollupImageUris[0] = "";
rollupImageUris[0] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkRollupTalent1.svg";
rollupImageUris[1] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkRollupTalent1.svg";
rollupImageUris[2] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkRollupTalent2.svg";
rollupImageUris[3] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkRollupTalent3.svg";


// Encode the JSON metadata
string memory defaultTokenJson = Base64.encode(
abi.encodePacked('{"name":"No Score", "description":"No contributions yet", "image": "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkRollupTalent1.svg"}')
);
string memory defaultTokenUri = string(abi.encodePacked("data:application/json;base64,", defaultTokenJson));


// Deploy ZK Rollups Badge
PassportDevZKBadge badgeRollups = new PassportDevZKBadge(resolver, easAddress);
PassportDevZKBadge badgeRollups = new PassportDevZKBadge(resolver, easAddress, defaultTokenUri);
badgeRollups.toggleAttester(gitcoinAttester, true);
badgeRollups.setEASAddress(easAddress);
badgeRollups.setLevelThresholds(levelThresholds);
Expand All @@ -60,7 +68,7 @@ contract DeployPassportDevZKBadge is Script {
// Set 2: ZK Infra

string[] memory infraImageUris = new string[](4);
infraImageUris[0] = "";
infraImageUris[0] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkInfraTalent1.svg";
infraImageUris[1] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkInfraTalent1.svg";
infraImageUris[2] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkInfraTalent2.svg";
infraImageUris[3] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkInfraTalent3.svg";
Expand All @@ -78,7 +86,7 @@ contract DeployPassportDevZKBadge is Script {
infraDescriptions[3] = "Contributed to ZK Infra projects";

// Deploy ZK Infra Badge
PassportDevZKBadge badgeInfra = new PassportDevZKBadge(resolver, easAddress);
PassportDevZKBadge badgeInfra = new PassportDevZKBadge(resolver, easAddress, defaultTokenUri);
badgeInfra.toggleAttester(gitcoinAttester, true);
badgeInfra.setEASAddress(easAddress);
badgeInfra.setLevelThresholds(levelThresholds);
Expand All @@ -88,7 +96,7 @@ contract DeployPassportDevZKBadge is Script {

// Set 3: ZK Privacy
string[] memory privacyImageUris = new string[](4);
privacyImageUris[0] = "";
privacyImageUris[0] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkPrivacyTalent1.svg";
privacyImageUris[1] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkPrivacyTalent1.svg";
privacyImageUris[2] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkPrivacyTalent2.svg";
privacyImageUris[3] = "https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkPrivacyTalent3.svg";
Expand All @@ -106,7 +114,7 @@ contract DeployPassportDevZKBadge is Script {
privacyDescriptions[3] = "Contributed to ZK privacy projects";

// Deploy ZK Privacy Badge
PassportDevZKBadge badgePrivacy = new PassportDevZKBadge(resolver, easAddress);
PassportDevZKBadge badgePrivacy = new PassportDevZKBadge(resolver, easAddress, defaultTokenUri);
badgePrivacy.toggleAttester(gitcoinAttester, true);
badgePrivacy.setEASAddress(easAddress);
badgePrivacy.setLevelThresholds(levelThresholds);
Expand All @@ -116,7 +124,7 @@ contract DeployPassportDevZKBadge is Script {


// Deploy ZK Privacy Badge
PassportDevZKBadge passportTestBadge = new PassportDevZKBadge(resolver, easAddress);
PassportDevZKBadge passportTestBadge = new PassportDevZKBadge(resolver, easAddress, defaultTokenUri);
passportTestBadge.toggleAttester(gitcoinAttester, true);
passportTestBadge.setEASAddress(easAddress);
passportTestBadge.setLevelThresholds(levelThresholds);
Expand Down
17 changes: 9 additions & 8 deletions src/PassportDevZKBadge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {ScrollBadgeAccessControl} from "@canvas/badge/extensions/ScrollBadgeAcce
import {ScrollBadgeSingleton} from "@canvas/badge/extensions/ScrollBadgeSingleton.sol";
import {IScrollBadgeUpgradeable} from "@canvas/badge/extensions/IScrollBadgeUpgradeable.sol";
import {ScrollBadgeCustomPayload} from "@canvas/badge/extensions/ScrollBadgeCustomPayload.sol";
import {ScrollBadgeDefaultURI} from "@canvas/badge/extensions/ScrollBadgeDefaultURI.sol";
import {Unauthorized, CannotUpgrade} from "@canvas/Errors.sol";
import {ScrollBadge} from "@canvas/badge/ScrollBadge.sol";
import {SchemaResolver, ISchemaResolver} from "@eas/contracts/resolver/SchemaResolver.sol";
Expand All @@ -28,7 +29,8 @@ contract PassportDevZKBadge is
ScrollBadgeAccessControl,
ScrollBadgeCustomPayload,
ScrollBadgeSingleton,
SchemaResolver
SchemaResolver,
ScrollBadgeDefaultURI
{
/// @notice The instance of the EAS contract
IEAS public eas;
Expand Down Expand Up @@ -83,7 +85,7 @@ contract PassportDevZKBadge is

/// @notice Initializes the PassportDevZKBadge contract
/// @param resolver_ The address of the resolver contract
constructor(address resolver_, address eas_) ScrollBadge(resolver_) SchemaResolver(IEAS(eas_)) Ownable() {
constructor(address resolver_, address eas_, string memory _defaultBadgeURI) ScrollBadge(resolver_) SchemaResolver(IEAS(eas_)) ScrollBadgeDefaultURI(_defaultBadgeURI) Ownable() {
upgradeSchema = _eas.getSchemaRegistry().register(
"uint256 updatedScore, bytes32[] providerHashes",
ISchemaResolver(address(this)), // resolver
Expand Down Expand Up @@ -176,11 +178,10 @@ contract PassportDevZKBadge is
return super.onRevokeBadge(attestation);
}

/// @inheritdoc ScrollBadge
/// @dev Generates the token URI for a given badge
/// @param uid The unique identifier of the badge
/// @return A string containing the token URI
function badgeTokenURI(bytes32 uid) public view override returns (string memory) {
/// @notice Returns the token URI corresponding to a certain badge UID.
/// @param uid The badge UID.
/// @return The badge token URI (same format as ERC721).
function getBadgeTokenURI(bytes32 uid) internal view override returns (string memory) {
address recipient = getAttestation(uid).recipient;
uint256 level = badgeLevel[recipient];
string memory name = badgeLevelNames[level];
Expand All @@ -192,7 +193,7 @@ contract PassportDevZKBadge is
abi.encodePacked('{"name":"', name, '", "description":"', description, '", "image": "', image, '"}')
);

return string(abi.encodePacked("data:application/json;base64,", tokenUriJson));
return string(abi.encodePacked("data:application/json;base64,", tokenUriJson));
}

/// @notice Return an attestation for a given UID
Expand Down
26 changes: 10 additions & 16 deletions test/TestPassportDevZKBadge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ contract TestPassportDevZKBadge is Test {
address constant unauthorizedAddress = 0x1111111111111111111111111111111111111111;

string constant defaultProviderHash = "GithubGuru";
string constant defaultBadgeUri = "defaultBadgeURI";

bytes32 constant revocationSchema = 0xba4934720e4c7fc2978acd7c8b4e9cb72288e72f835bd19b2eb4cac99d79d220;

function setUp() public {
zkBadge = new PassportDevZKBadge(resolver, easAddress);
zkBadge = new PassportDevZKBadge(resolver, easAddress, defaultBadgeUri);

upgradeSchema = zkBadge.upgradeSchema();

Expand Down Expand Up @@ -312,21 +313,6 @@ contract TestPassportDevZKBadge is Test {
zkBadge.setBadgeLevelImageURIs(newURIs);
}

function test_tokenURILevel0() public {
// string memory uri = zkBadge.badgeTokenURI(address(0));

// Uncomment and update the following assertion once the exact URI format is confirmed
// assertEq(
// uri,
// string.concat(
// "data:application/json;base64,",
// string(Base64.encode(
// '{"name":"Passport ZK Badge", "description":"Default description", "image": "URIdefault"}'
// ))
// )
// );
}

function test_successful_revocation() public {
// Issue a badge
uint256 currentLevel = 1;
Expand Down Expand Up @@ -399,4 +385,12 @@ contract TestPassportDevZKBadge is Test {
// Verify that the badge level remains unchanged
assertEq(zkBadge.badgeLevel(user), 1);
}

function test_default_token_uri() public {
string memory defaultBadgeUriFromContract = zkBadge.defaultBadgeURI();
assertEq(defaultBadgeUriFromContract, defaultBadgeUri);

string memory zeroBadgeUri = zkBadge.badgeTokenURI(bytes32(0));
assertEq(zeroBadgeUri, defaultBadgeUri);
}
}