-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: As a Dev, I want the EASPortal to be based on the AbstractPortal (
#106)
- Loading branch information
Showing
7 changed files
with
151 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,81 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.21; | ||
|
||
import { Initializable } from "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; | ||
// solhint-disable-next-line max-line-length | ||
import { IERC165Upgradeable } from "openzeppelin-contracts-upgradeable/contracts/utils/introspection/ERC165Upgradeable.sol"; | ||
import { AttestationRegistry } from "../AttestationRegistry.sol"; | ||
import { ModuleRegistry } from "../ModuleRegistry.sol"; | ||
import { SchemaRegistry } from "../SchemaRegistry.sol"; | ||
import { AbstractPortal } from "../interface/AbstractPortal.sol"; | ||
import { Attestation, AttestationPayload, Portal } from "../types/Structs.sol"; | ||
|
||
struct AttestationRequestData { | ||
address recipient; | ||
uint64 expirationTime; | ||
bool revocable; | ||
bytes32 refUID; | ||
bytes data; | ||
uint256 value; | ||
} | ||
|
||
struct AttestationRequest { | ||
bytes32 schema; | ||
AttestationRequestData data; | ||
} | ||
|
||
abstract contract EASAbstractPortal { | ||
function attest(AttestationRequest memory attestationRequest) external payable virtual; | ||
} | ||
|
||
/** | ||
* @title EAS Portal | ||
* @author Consensys | ||
* @notice This contract aims to integrate with dapps that are already integrated with EAS | ||
* @notice This contract aims to provide a default portal | ||
*/ | ||
contract EASPortal is Initializable, EASAbstractPortal, IERC165Upgradeable { | ||
AttestationRegistry public attestationRegistry; | ||
|
||
/** | ||
* @notice Contract initialization | ||
*/ | ||
function initialize(address _attestationRegistry) public initializer { | ||
// Store registries addresses | ||
attestationRegistry = AttestationRegistry(_attestationRegistry); | ||
contract EASPortal is AbstractPortal { | ||
struct AttestationRequestData { | ||
address recipient; | ||
uint64 expirationTime; | ||
bool revocable; | ||
bytes32 refUID; | ||
bytes data; | ||
uint256 value; | ||
} | ||
|
||
struct AttestationRequest { | ||
bytes32 schema; | ||
AttestationRequestData data; | ||
} | ||
|
||
/** | ||
* @notice attest the schema with given attestationPayload and validationPayload | ||
* @dev Runs all modules for the portal and stores the attestation in AttestationRegistry | ||
*/ | ||
function attest(AttestationRequest memory attestationRequest) external payable override { | ||
AttestationRequestData memory attestationRequestData = attestationRequest.data; | ||
function _beforeAttest(AttestationPayload memory attestation, uint256 value) internal override {} | ||
|
||
function _afterAttest(Attestation memory attestation) internal override {} | ||
|
||
function _onRevoke(bytes32 attestationId, bytes32 replacedBy) internal override {} | ||
|
||
function _onBulkAttest( | ||
AttestationPayload[] memory attestationsPayloads, | ||
bytes[][] memory validationPayloads | ||
) internal override {} | ||
|
||
function _onBulkRevoke(bytes32[] memory attestationIds, bytes32[] memory replacedBy) internal override {} | ||
|
||
function attest(AttestationRequest memory attestationRequest) external payable { | ||
bytes[] memory validationPayload = new bytes[](0); | ||
|
||
AttestationPayload memory attestationPayload = AttestationPayload( | ||
attestationRequest.schema, | ||
abi.encodePacked(attestationRequestData.recipient), | ||
uint256(attestationRequestData.expirationTime), | ||
attestationRequestData.data | ||
abi.encodePacked(attestationRequest.data.recipient), | ||
uint256(attestationRequest.data.expirationTime), | ||
attestationRequest.data.data | ||
); | ||
|
||
attestationRegistry.attest(attestationPayload); | ||
super.attest(attestationPayload, validationPayload); | ||
} | ||
|
||
function bulkAttest(AttestationRequest[] memory attestationsRequests) external payable { | ||
AttestationPayload[] memory attestationsPayloads = new AttestationPayload[](attestationsRequests.length); | ||
bytes[][] memory validationPayloads = new bytes[][](attestationsRequests.length); | ||
|
||
for (uint i = 0; i < attestationsRequests.length; i++) { | ||
attestationsPayloads[i] = AttestationPayload( | ||
attestationsRequests[i].schema, | ||
abi.encodePacked(attestationsRequests[i].data.recipient), | ||
uint256(attestationsRequests[i].data.expirationTime), | ||
attestationsRequests[i].data.data | ||
); | ||
|
||
validationPayloads[i] = new bytes[](0); | ||
} | ||
|
||
super.bulkAttest(attestationsPayloads, validationPayloads); | ||
} | ||
|
||
function revoke(bytes32 /*attestationId*/, bytes32 /*replacedBy*/) external pure override { | ||
revert("No revoking"); | ||
} | ||
|
||
/** | ||
* @notice Implements supports interface method declaring it is an EASAbstractPortal | ||
*/ | ||
function supportsInterface(bytes4 interfaceID) public pure override returns (bool) { | ||
return interfaceID == type(EASAbstractPortal).interfaceId || interfaceID == type(IERC165Upgradeable).interfaceId; | ||
function bulkRevoke(bytes32[] memory /*attestationIds*/, bytes32[] memory /*replacedBy*/) external pure override { | ||
revert("No bulk revoking"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.