Skip to content

Commit

Permalink
chore: smart contract improvements (#16)
Browse files Browse the repository at this point in the history
* feat: general improvements

* feat: GitcoinVerifier improvements

* chore: remove easContractAddress variable

* Fixing configuration & GitcoinVerifier

* feat: test withdraw function in GitcoinVerifier

* chore: pull changes from main

---------

Co-authored-by: Gerald Iakobinyi-Pich <[email protected]>
  • Loading branch information
chibie and nutrina authored May 31, 2023
1 parent 7ca49bf commit 15c1a62
Show file tree
Hide file tree
Showing 8 changed files with 5,512 additions and 15,494 deletions.
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

0 comments on commit 15c1a62

Please sign in to comment.