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

chore: smart contract improvements #16

Merged
merged 6 commits into from
May 31, 2023
Merged
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
107 changes: 55 additions & 52 deletions contracts/GitcoinAttester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,65 @@
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/access/Ownable.sol";
import {AttestationRequest, AttestationRequestData, IEAS, Attestation, MultiAttestationRequest} from "@ethereum-attestation-service/eas-contracts/contracts/IEAS.sol";
import { AttestationRequest, AttestationRequestData, IEAS, Attestation, MultiAttestationRequest } from "@ethereum-attestation-service/eas-contracts/contracts/IEAS.sol";

/**
* @title GitcoinAttester
* @dev A contract that allows a Verifier contract to add passport information for users using Ethereum Attestation Service.
*/
contract GitcoinAttester is Ownable {
address private easContractAddress; // The address of the EAS contract.
mapping(address => bool) public verifiers; // An allow-list of Verifiers that are authorized and trusted to call the addPassport function.

IEAS eas; // The instance of the EAS contract.

event VerifierAdded(address verifier); // Emitted when a verifier is added to the allow-list.
event VerifierRemoved(address verifier); // Emitted when a verifier is removed from the allow-list.

/**
* @dev Adds a verifier to the allow-list.
* @param _verifier The address of the verifier to add. It must be a Gnosis Safe contract.
*/
function addVerifier(address _verifier) public onlyOwner {
require(!verifiers[_verifier], "Verifier already added");
verifiers[_verifier] = true;
emit VerifierAdded(_verifier);
}

/**
* @dev Removes a verifier from the allow-list.
* @param _verifier The address of the verifier to remove.
*/
function removeVerifier(address _verifier) public onlyOwner {
require(verifiers[_verifier], "Verifier does not exist");
verifiers[_verifier] = false;
emit VerifierRemoved(_verifier);
}

/**
* @dev Sets the address of the EAS contract.
* @param _easContractAddress The address of the EAS contract.
*/
function setEASAddress(address _easContractAddress) public onlyOwner {
easContractAddress = _easContractAddress;
eas = IEAS(easContractAddress);
}

/**
* @dev Adds passport information for a user using EAS
* @param multiAttestationRequest An array of `MultiAttestationRequest` structures containing the user's passport information.
*/
function addPassport(
MultiAttestationRequest[] calldata multiAttestationRequest
) public payable virtual returns (bytes32[] memory) {
require(
verifiers[msg.sender],
"Only authorized verifiers can call this function"
);

return eas.multiAttest(multiAttestationRequest);
}
// An allow-list of Verifiers that are authorized and trusted to call the addPassport function.
mapping(address => bool) public verifiers;

// The instance of the EAS contract.
IEAS eas;

// Emitted when a verifier is added to the allow-list.
event VerifierAdded(address verifier);

// Emitted when a verifier is removed from the allow-list.
event VerifierRemoved(address verifier);

/**
* @dev Adds a verifier to the allow-list.
* @param _verifier The address of the verifier to add. It must be a Gnosis Safe contract.
*/
function addVerifier(address _verifier) public onlyOwner {
require(!verifiers[_verifier], "Verifier already added");
verifiers[_verifier] = true;
emit VerifierAdded(_verifier);
}

/**
* @dev Removes a verifier from the allow-list.
* @param _verifier The address of the verifier to remove.
*/
function removeVerifier(address _verifier) public onlyOwner {
require(verifiers[_verifier], "Verifier does not exist");
verifiers[_verifier] = false;
emit VerifierRemoved(_verifier);
}

/**
* @dev Sets the address of the EAS contract.
* @param _easContractAddress The address of the EAS contract.
*/
function setEASAddress(address _easContractAddress) public onlyOwner {
eas = IEAS(_easContractAddress);
}

/**
* @dev Adds passport information for a user using EAS
* @param multiAttestationRequest An array of `MultiAttestationRequest` structures containing the user's passport information.
*/
function addPassport(
MultiAttestationRequest[] calldata multiAttestationRequest
) public payable virtual returns (bytes32[] memory) {
require(
verifiers[msg.sender],
"Only authorized verifiers can call this function"
);

return eas.multiAttest(multiAttestationRequest);
}
}
Loading