Skip to content
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
19 changes: 3 additions & 16 deletions contracts/resolverEAS/Resolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,19 @@ contract Resolver is IResolver, Ownable {
/// @inheritdoc IResolver
function attest(Attestation calldata attestation) external payable onlyEAS returns (bool) {
if (address(trustfulResolver) == address(0)) revert InvalidContractAddress();
if (attestation.recipient != attestation.attester) revert InvalidGrantOwner();
if (attestation.recipient != attestation.attester) revert InvalidGrantOwner();
if (attestation.expirationTime != 0) revert InvalidExpirationTime();
if (attestation.revocable != false) revert InvalidRevocability();

(bytes32 grantUID, bytes32[] memory badgeIds, uint8[] memory badgesScores) = abi.decode(
(bytes32 grantUID, bytes32[] memory badgeIds, uint8[] memory badgesScores, string memory grantProgramUID) = abi.decode(
attestation.data,
(bytes32, bytes32[], uint8[])
(bytes32, bytes32[], uint8[], string)
);

if (attestation.refUID != grantUID) revert InvalidRefUID();

// fetching each data separately because the grantRegistry might be upgraded someday
// and this way we allow backwards compatibility
address grantee = grantRegistry.getGranteeAddress(grantUID);
uint256 grantProgramUID = grantRegistry.getGrantProgramUID(grantUID);
IGrantRegistry.Status status = grantRegistry.getStatus(grantUID);

// check if badges exists in the registry
for (uint256 i = 0; i < badgeIds.length; i++) {
Expand All @@ -75,16 +72,6 @@ contract Resolver is IResolver, Ownable {
}
}

// check if grantee is the attester
if (grantee != attestation.attester) {
revert InvalidGrantOwner();
}

// rejected grants cannot be reviewed
if (status == IGrantRegistry.Status.Rejected) {
revert InvalidGrantReview();
}

// create a new review with a story
bool success = trustfulResolver.createStory(
grantUID,
Expand Down
2 changes: 1 addition & 1 deletion contracts/resolverEAS/interfaces/ITrustfulResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface ITrustfulResolver {
function createStory(
bytes32 grantUID,
bytes32 txUID,
uint256 grantProgramUID,
string calldata grantProgramUID,
bytes32[] calldata badges,
uint8[] calldata scores
) external returns (bool success);
Expand Down
18 changes: 9 additions & 9 deletions contracts/resolverTrustful/Resolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
/// @author KarmaGap | 0xneves.eth
/// @notice This is the implementation of the Trustful Resolver contract.
/// This contract is used to resolve scores and badges for Karma Gap Reviews.
contract Resolver is IResolver, Ownable {
contract Resolver is IResolver, Ownable {
/// Trustful Scorer contract address
address public trustfulScorer;
/// EAS Resolver contract address
Expand All @@ -25,7 +25,7 @@ contract Resolver is IResolver, Ownable {
/// @dev We don't expect this to grow too large
mapping(bytes32 => GrantStory[]) private _stories;
/// Maps grant program IDs to their reviews
mapping(uint256 => GrantProgram) private _grantPrograms;
mapping(string => GrantProgram) private _grantPrograms;

/// @param _scorerAddr Address of the Trustful Scorer contract.
/// @param _easResolverAddr Address of the EAS Resolver contract.
Expand All @@ -38,7 +38,7 @@ contract Resolver is IResolver, Ownable {
function createStory(
bytes32 grantUID,
bytes32 txUID,
uint256 grantProgramUID,
string calldata grantProgramUID,
bytes32[] calldata badges,
uint8[] calldata scores
) external returns (bool) {
Expand Down Expand Up @@ -174,10 +174,10 @@ contract Resolver is IResolver, Ownable {
}

/// @inheritdoc IResolver
function scoreOf(bytes memory data) external view returns (bool success, uint256 score) {
uint256 grantProgramUID = abi.decode(data, (uint256));
function scoreOf(bytes calldata data) external view returns (bool success, uint256 score) {
string memory grantProgramUID = abi.decode(data, (string));
return (true, getGrantProgramAverageScore(grantProgramUID));
}
}

/// @inheritdoc IResolver
function getGrantStories(bytes32 grantUID) external view returns (GrantStory[] memory) {
Expand All @@ -199,20 +199,20 @@ contract Resolver is IResolver, Ownable {

/// @inheritdoc IResolver
function getGrantProgramValidReviewCount(
uint256 grantProgramUID
string calldata grantProgramUID
) external view returns (uint256) {
return _grantPrograms[grantProgramUID].validReviewCount;
}

/// @inheritdoc IResolver
function getGrantProgramTotalReviewCount(
uint256 grantProgramUID
string calldata grantProgramUID
) external view returns (uint256) {
return _grantPrograms[grantProgramUID].reviewCount;
}

/// @inheritdoc IResolver
function getGrantProgramAverageScore(uint256 grantProgramUID) public view returns (uint256) {
function getGrantProgramAverageScore(string memory grantProgramUID) public view returns (uint256) {
GrantProgram memory grantProgram = _grantPrograms[grantProgramUID];
if (grantProgram.validReviewCount == 0) revert GrantProgramNotReviewed();
return grantProgram.averageScore;
Expand Down
14 changes: 7 additions & 7 deletions contracts/resolverTrustful/interfaces/IResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface IResolver {
event StoryCreated(
bytes32 indexed grantUID,
bytes32 indexed txUID,
uint256 indexed grantProgramUID,
string indexed grantProgramUID,
uint256 timestamp,
uint256 averageScore,
uint256 reviewCount
Expand Down Expand Up @@ -66,7 +66,7 @@ interface IResolver {
function createStory(
bytes32 grantUID,
bytes32 txUID,
uint256 grantProgramUID,
string calldata grantProgramUID,
bytes32[] calldata badges,
uint8[] calldata scores
) external returns (bool success);
Expand All @@ -85,11 +85,11 @@ interface IResolver {
function setEASResolverAddress(address newEasResolverAddr) external;

/// @dev This implementation is required by {TrustfulScorer}.
/// @param grantProgramUID Abi Encoded grant program UID.
/// @param data Abi Encoded grant program UID.
/// @return success If the operation succeeded.
/// @return score The average score of the grant program.
function scoreOf(
bytes memory grantProgramUID
bytes calldata data
) external view returns (bool success, uint256 score);

/// @param grantUID Unique identifier of the grant.
Expand All @@ -110,11 +110,11 @@ interface IResolver {

/// @param grantProgramUID The ID of the progam.
/// @return validReviewCount The review count for the grant program.
function getGrantProgramValidReviewCount(uint256 grantProgramUID) external view returns (uint256);
function getGrantProgramValidReviewCount(string calldata grantProgramUID) external view returns (uint256);

/// @param grantProgramUID The ID of the progam.
/// @return reviewCount The review count for the grant program.
function getGrantProgramTotalReviewCount(uint256 grantProgramUID) external view returns (uint256);
function getGrantProgramTotalReviewCount(string calldata grantProgramUID) external view returns (uint256);

/// @notice Gets the average score of a grant program.
///
Expand All @@ -128,5 +128,5 @@ interface IResolver {
///
/// @param grantProgramUID The ID of the progam.
/// @return averageScore The average score of the grant program.
function getGrantProgramAverageScore(uint256 grantProgramUID) external view returns (uint256);
function getGrantProgramAverageScore(string memory grantProgramUID) external view returns (uint256);
}