Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article explores ERC7794, which proposes a mechanism for centrally managing and tracking grants across multiple blockchains.

The article translates, summarizes, and expands on the specification linked below.

Overview

ERC7794 proposes a Grant Registry contract for centrally managing grants across multiple blockchains. The contract provides a framework for managing project funding and streamlines grant registration, administration, and tracking.

Grant data is organized into immutable and updatable fields. The contract also provides a modular mechanism for managing funding disbursements and allows links to files stored offchain (outside the blockchain) to be associated with grants.

The contract emits events throughout the grant lifecycle, allowing external protocols to retrieve grant data efficiently and maintain transparency. This improves interoperability between projects and grant programs and helps assess their outcomes more effectively.

Motivation

At the time of the proposal, the Ethereum ecosystem lacked a unified mechanism for managing grants across multiple blockchains. Individual grant programs therefore adopted different interfaces and management methods, creating the following problems for funders and recipients.

  • Lack of transparency
    • It is difficult to track grant progress and how funds are used.
  • Complicated disbursement management
    • It is not immediately apparent how much funding has been allocated to each project.
  • Difficulty evaluating grant effectiveness
    • Combining data across programs is difficult, making it hard to analyze the impact of grants.

Another challenge is the lack of unified management when projects and developers operating on different blockchains receive grants. Existing mechanisms require different procedures on each chain, raising barriers to funding and potentially hindering project growth.

The Grant Registry contract addresses these problems by providing a framework for registering and managing all grants in one place. It enables efficient tracking throughout the grant lifecycle and improves interoperability between chains and programs.

Standardized data makes it easier to measure grant outcomes and conduct more detailed analysis. This helps assess the impact of grants on individual projects and the broader ecosystem, improving transparency and decision-making.

Specification

registerGrant

js
function registerGrant(
    uint256 id,
    uint256 chainid,
    string memory community,
    address grantManager
) external returns (bytes32);

Overview

registerGrant registers a new grant.

Details

Calling this function registers a new grant. It generates a unique grantId for each grant and stores the blockchain on which the grant is offered (chainid), the community name (community), and the manager (grantManager).

The following conditions must be met.

  • The grantManager address must not be 0x0.
  • The community label must not be empty.
  • The grant ID (grantId) must not duplicate an existing one.

A successful call emits the GrantRegistered event.

Parameters

  • id
    • Unique identifier of the grant program.
  • chainid
    • Chain ID of the blockchain on which the grant is registered.
  • community
    • Name of the community providing the grant.
  • grantManager
    • Address of the grant manager.

Returns

  • grantId
    • A bytes32 value that uniquely identifies the grant.

transferOwnership

js
function transferOwnership(bytes32 grantId, address newGrantManager) external;

Overview

transferOwnership transfers authority to manage a grant to another address.

Details

Only the current grantManager can call this function. Transferring authority to newGrantManager makes the new manager responsible for grant operations and disbursements. newGrantManager must not be 0x0.

A successful call emits the OwnershipTransferred event.

Parameters

  • grantId
    • Unique identifier of the grant whose management authority is being transferred.
  • newGrantManager
    • Address of the new grant manager.

addGrantee

js
function addGrantee(bytes32 grantId, address grantee) external;

Overview

addGrantee registers a new grant recipient (grantee).

Details

Only grantManager can execute this function. The grantee to register must not be 0x0, and an already registered grantee cannot be added again.

A successful call emits the GranteeAdded event.

Parameters

  • grantId
    • Unique identifier of the grant.
  • grantee
    • Address of the recipient to register.

removeGrantee

js
function removeGrantee(bytes32 grantId, address grantee) external;

Overview

removeGrantee removes an existing grant recipient.

Details

Only grantManager can execute this function. The grantee to remove must already be registered for the grant.

A successful call emits the GranteeRemoved event.

Parameters

  • grantId
    • Unique identifier of the grant.
  • grantee
    • Address of the recipient to remove.

setStartDate

js
function setStartDate(bytes32 grantId, uint256 startDate) external;

Overview

setStartDate sets a grant's start date.

Details

Only grantManager can execute this function. The grant's start date (startDate) must be greater than or equal to block.timestamp.

A successful call emits the StartDateSet event.

Parameters

  • grantId
    • Unique identifier of the grant.
  • startDate
    • Grant start date and time (Unix timestamp).

addMilestoneDate

js
function addMilestoneDate(bytes32 grantId, uint256 milestoneDate) external;

Overview

addMilestoneDate adds a new milestone date.

Details

Only grantManager can execute this function. The milestoneDate to add must not duplicate a previously registered date.

A successful call emits the MilestoneDateAdded event.

Parameters

  • grantId
    • Unique identifier of the grant.
  • milestoneDate
    • Date of the milestone to add (Unix timestamp).

addDisbursement

js
function addDisbursement(
    bytes32 grantId,
    uint256 milestoneDate,
    address fundingToken,
    uint256 fundingAmount
) external;

Overview

addDisbursement configures a disbursement for a particular milestone.

Details

Only grantManager can execute this function. The specified milestoneDate must be valid and registered for the grant.

A successful call emits the DisbursementAdded event.

Parameters

  • grantId
    • Unique identifier of the grant.
  • milestoneDate
    • Date of the milestone associated with the disbursement (Unix timestamp).
  • fundingToken
    • Address of the token used for the disbursement.
  • fundingAmount
    • Amount of tokens to disburse.

removeDisbursement

js
function removeDisbursement(bytes32 grantId, uint256 milestoneDate) external;

Overview

removeDisbursement removes a disbursement associated with a specified milestone.

Details

Only grantManager can execute this function. The specified milestoneDate must exist as a milestone for the grant.

A successful call emits the DisbursementRemoved event.

Parameters

  • grantId
    • Unique identifier of the grant.
  • milestoneDate
    • Date of the milestone associated with the disbursement to remove (Unix timestamp).

setDisbursementStatus

js
function setDisbursementStatus(
    bytes32 grantId,
    uint256 milestoneDate,
    bool isDisbursed
) external;

Overview

setDisbursementStatus updates the disbursement status of a specified milestone.

Details

Only grantManager can execute this function. The specified milestoneDate must exist as a milestone for the grant.

A successful call emits the DisbursementMade event.

Parameters

  • grantId
    • Unique identifier of the grant.
  • milestoneDate
    • Date of the milestone associated with the disbursement whose status is being updated (Unix timestamp).
  • isDisbursed
    • A value of true indicates that funds have been disbursed.

js
function addExternalLink(bytes32 grantId, string memory link) external;

Overview

addExternalLink adds an external link related to a grant.

Details

Only grantManager can execute this function. The link to add must not be an empty string.

A successful call emits the ExternalLinkAdded event.

Parameters

  • grantId
    • Unique identifier of the grant.
  • link
    • URL of the external link to add.

js
function removeExternalLink(bytes32 grantId, uint256 index) external;

Overview

removeExternalLink removes an external link related to a grant.

Details

Only grantManager can execute this function. The specified index must be within the valid range of the array of external links associated with the grant.

A successful call emits the ExternalLinkRemoved event.

Parameters

  • grantId
    • Unique identifier of the grant.
  • index
    • Index of the external link to remove from the array.

getGrant

js
function getGrant(bytes32 grantId) external view returns (Grant memory);

Overview

getGrant retrieves detailed information about a specified grant.

Details

It retrieves the grant's basic information (id, chainid, and community).

Parameters

  • grantId
    • Unique identifier of the grant.

Returns

  • Grant
    • Structure containing detailed grant information.

getGrantManager

js
function getGrantManager(bytes32 grantId) external view returns (address);

Overview

getGrantManager retrieves the current manager address for a specified grant.

Details

It returns the address of the grant manager (grantManager).

Parameters

  • grantId
    • Unique identifier of the grant.

Returns

  • grantManager
    • Address of the grant manager.

getGrantees

js
function getGrantees(bytes32 grantId) external view returns (address[] memory);

Overview

getGrantees retrieves the list of recipients of a grant.

Details

It retrieves the list of recipient (grantees) addresses for the specified grant.

Parameters

  • grantId
    • Unique identifier of the grant.

Returns

  • address[]
    • List of recipient addresses.

getMilestonesDates

js
function getMilestonesDates(bytes32 grantId) external view returns (uint256, uint256[] memory);

Overview

getMilestonesDates retrieves the grant's start date and milestone schedule.

Details

It returns the grant's start date (startDate) and the list of configured milestone dates.

Parameters

  • grantId
    • Unique identifier of the grant.

Returns

  • startDate
    • Grant start date (Unix timestamp).
  • milestoneDates
    • List of configured milestone dates.

getDisbursement

js
function getDisbursement(bytes32 grantId, uint256 milestoneDate) external view returns (Disbursements memory);

Overview

getDisbursement retrieves details of a disbursement for a particular milestone.

Details

It retrieves the disbursement information (fundingToken, fundingAmount, and isDisbursed) associated with the specified milestoneDate.

Parameters

  • grantId
    • Unique identifier of the grant.
  • milestoneDate
    • Date of the milestone whose disbursement is being retrieved (Unix timestamp).

Returns

  • Disbursements
    • Structure containing detailed disbursement information.

js
function getExternalLinks(bytes32 grantId) external view returns (string[] memory);

Overview

getExternalLinks retrieves the external links associated with a grant.

Details

It returns the list of external links added to the specified grant.

Parameters

  • grantId
    • Unique identifier of the grant.

Returns

  • string[]
    • List of external links associated with the grant.

Contract

js
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

interface IGrantRegistry {
  /**
   * @dev Thrown when the community name length is invalid (e.g., too short or too long).
   */
  error InvalidCommunityNameLength();

  /**
   * @dev Thrown when the caller is not the current grant manager.
   */
  error InvalidGrantManager();

  /**
   * @dev Thrown when a grant is already registered with the provided ID.
   */
  error GrantAlreadyRegistered();

  /**
   * @dev Thrown when attempting to add a grantee that is already present in the set.
   */
  error GranteeAlreadyAdded();

  /**
   * @dev Thrown when attempting to remove a grantee that is not found in the set.
   */
  error GranteeNotFound();

  /**
   * @dev Thrown when attempting to add or reference an invalid external link.
   */
  error InvalidExternalLink();

  /**
   * @dev Thrown when an invalid index is provided (e.g., out of bounds for an array).
   */
  error InvalidIndex();

  /**
   * @dev Thrown when a milestone date is invalid (e.g., earlier than the grant's start date).
   */
  error InvalidStartDate();

  /**
   * @dev Thrown when attempting to add a milestone date that is already present.
   */
  error MilestoneDateAlreadyAdded();

  /**
   * @dev Thrown when attempting to remove or reference a milestone date that is not found.
   */
  error MilestoneDateNotFound();

  /**
   * @dev Emitted when a new grant is registered.
   * @param grantId The unique identifier for the grant.
   * @param id The grant's unique numeric ID.
   * @param chainid The chain ID where the grant is registered.
   * @param community The name of the community that issued the grant.
   * @param grantManager The address of the grant manager.
   */
  event GrantRegistered(
    bytes32 indexed grantId,
    uint256 indexed id,
    uint256 chainid,
    string indexed community,
    address grantManager
  );

  /**
   * @dev Emitted when the ownership of a grant is transferred.
   * @param grantId The unique identifier of the grant.
   * @param newGrantManager The address of the new grant manager.
   */
  event OwnershipTransferred(
    bytes32 indexed grantId,
    address indexed newGrantManager
  );

  /**
   * @dev Emitted when a new grantee is added to the grant.
   * @param grantId The unique identifier of the grant.
   * @param grantee The address of the new grantee.
   */
  event GranteeAdded(bytes32 indexed grantId, address indexed grantee);

  /**
   * @dev Emitted when a grantee is removed from the grant.
   * @param grantId The unique identifier of the grant.
   * @param grantee The address of the removed grantee.
   */
  event GranteeRemoved(bytes32 indexed grantId, address indexed grantee);

  /**
   * @dev Emitted when the start date of a grant is set.
   * @param grantId The unique identifier of the grant.
   * @param startDate The timestamp representing the start date.
   */
  event StartDateSet(bytes32 indexed grantId, uint256 startDate);

  /**
   * @dev Emitted when a new milestone date is added to the grant.
   * @param grantId The unique identifier of the grant.
   * @param milestoneDate The timestamp of the added milestone.
   */
  event MilestoneDateAdded(bytes32 indexed grantId, uint256 milestoneDate);

  /**
   * @dev Emitted when a milestone date is removed from the grant.
   * @param grantId The unique identifier of the grant.
   * @param milestoneDate The timestamp of the removed milestone.
   */
  event MilestoneDateRemoved(bytes32 indexed grantId, uint256 milestoneDate);

  /**
   * @dev Emitted when a disbursement is added to a milestone.
   * @param grantId The unique identifier of the grant.
   * @param milestoneDate The timestamp of the milestone.
   * @param fundingToken The token used for the disbursement.
   * @param fundingAmount The amount of the disbursement.
   */
  event DisbursementAdded(
    bytes32 indexed grantId,
    uint256 milestoneDate,
    address indexed fundingToken,
    uint256 fundingAmount
  );

  /**
   * @dev Emitted when a disbursement is removed from a milestone.
   * @param grantId The unique identifier of the grant.
   * @param milestoneDate The timestamp of the milestone.
   */
  event DisbursementRemoved(bytes32 indexed grantId, uint256 milestoneDate);

  /**
   * @dev Emitted when a disbursement status is updated.
   * @param grantId The unique identifier of the grant.
   * @param milestoneDate The timestamp of the milestone.
   * @param isDisbursed Boolean indicating if the disbursement has been made.
   */
  event DisbursementMade(
    bytes32 indexed grantId,
    uint256 milestoneDate,
    bool isDisbursed
  );

  /**
   * @dev Emitted when an external link is added to the grant.
   * @param grantId The unique identifier of the grant.
   * @param link The external URL added.
   */
  event ExternalLinkAdded(bytes32 indexed grantId, string link);

  /**
   * @dev Emitted when an external link is removed from the grant.
   * @param grantId The unique identifier of the grant.
   * @param link The external URL removed.
   */
  event ExternalLinkRemoved(bytes32 indexed grantId, string link);

  /**
   * @dev Registers a new grant with the provided details. `grantId` is generated by hashing the grant
   * details and the current timestamp.
   *
   * Requirements:
   *
   * - The `grantManager` address must not be the zero address.
   * - The `community` name must not be empty.
   * - The grant must not already be registered.
   *
   * Emits a {GrantRegistered} event.
   *
   * @param id The unique identifier for the grant program.
   * @param chainid The chain ID where the grant is being registered.
   * @param community The name of the community or protocol issuing the grant.
   * @param grantManager The address of the grant manager.
   * @return The generated `grantId` as a bytes32 value.
   */
  function registerGrant(
    uint256 id,
    uint256 chainid,
    string memory community,
    address grantManager
  ) external returns (bytes32);

  /**
   * @dev Transfers ownership of the grant to a new grant manager.
   *
   * Requirements:
   *
   * - The caller must be the current grant manager.
   * - The `newGrantManager` address must not be the zero address.
   *
   * Emits an {OwnershipTransferred} event.
   *
   * @param grantId The unique identifier of the grant.
   * @param newGrantManager The address of the new grant manager.
   */
  function transferOwnership(bytes32 grantId, address newGrantManager) external;

  /**
   * @dev Adds a new grantee to the grant.
   *
   * Requirements:
   *
   * - The caller must be the current grant manager.
   * - The `grantee` address must not be the zero address.
   *
   * Emits a {GranteeAdded} event.
   *
   * @param grantId The unique identifier of the grant.
   * @param grantee The address of the grantee to be added.
   */
  function addGrantee(bytes32 grantId, address grantee) external;

  /**
   * @dev Removes an existing grantee from the grant.
   *
   * Requirements:
   *
   * - The caller must be the current grant manager.
   * - The `grantee` address must be present in the grant.
   *
   * Emits a {GranteeRemoved} event.
   *
   * @param grantId The unique identifier of the grant.
   * @param grantee The address of the grantee to be removed.
   */
  function removeGrantee(bytes32 grantId, address grantee) external;

  /**
   * @dev Sets the start date for the grant.
   *
   * Requirements:
   *
   * - The caller must be the current grant manager.
   *
   * Emits a {StartDateSet} event.
   *
   * @param grantId The unique identifier of the grant.
   * @param startDate The timestamp representing the start date.
   */
  function setStartDate(bytes32 grantId, uint256 startDate) external;

  /**
   * @dev Adds a new milestone date for the grant.
   *
   * Requirements:
   *
   * - The caller must be the current grant manager.
   * - The milestone date must not already exist in the grant.
   *
   * Emits a {MilestoneDateAdded} event.
   *
   * @param grantId The unique identifier of the grant.
   * @param milestoneDate The timestamp representing the milestone date.
   */
  function addMilestoneDate(bytes32 grantId, uint256 milestoneDate) external;

  /**
   * @dev Removes a milestone date from the grant.
   *
   * Requirements:
   *
   * - The caller must be the current grant manager.
   * - The milestone date must exist in the grant.
   *
   * Emits a {MilestoneDateRemoved} event.
   *
   * @param grantId The unique identifier of the grant.
   * @param milestoneDate The timestamp representing the milestone date to be removed.
   */
  function removeMilestoneDate(bytes32 grantId, uint256 milestoneDate) external;

  /**
   * @dev Ovewrites a disbursement for a specific milestone.
   *
   * Requirements:
   *
   * - The caller must be the current grant manager.
   * - The milestone date must exist in the grant.
   *
   * Emits a {DisbursementAdded} event.
   *
   * @param grantId The unique identifier of the grant.
   * @param milestoneDate The milestone date associated with the disbursement.
   * @param fundingToken The address of the token used for funding.
   * @param fundingAmount The amount of tokens to be disbursed.
   */
  function addDisbursement(
    bytes32 grantId,
    uint256 milestoneDate,
    address fundingToken,
    uint256 fundingAmount
  ) external;

  /**
   * @dev Removes a disbursement for a specific milestone.
   *
   * Requirements:
   *
   * - The caller must be the current grant manager.
   * - The milestone date must exist in the grant.
   *
   * Emits a {DisbursementRemoved} event.
   *
   * @param grantId The unique identifier of the grant.
   * @param milestoneDate The milestone date associated with the disbursement.
   */
  function removeDisbursement(bytes32 grantId, uint256 milestoneDate) external;

  /**
   * @dev Updates the disbursement status for a specific milestone.
   *
   * Requirements:
   *
   * - The caller must be the current grant manager.
   * - The milestone date must exist in the grant.
   *
   * Emits a {DisbursementMade} event.
   *
   * @param grantId The unique identifier of the grant.
   * @param milestoneDate The milestone date associated with the disbursement.
   * @param isDisbursed A boolean value indicating if the disbursement has been made.
   */
  function setDisbursementStatus(
    bytes32 grantId,
    uint256 milestoneDate,
    bool isDisbursed
  ) external;

  /**
   * @dev Adds an external link related to the grant.
   *
   * Requirements:
   *
   * - The caller must be the current grant manager.
   * - The link must not be empty.
   *
   * Emits an {ExternalLinkAdded} event.
   *
   * @param grantId The unique identifier of the grant.
   * @param link The external URL to be added.
   */
  function addExternalLink(bytes32 grantId, string memory link) external;

  /**
   * @dev Removes an external link associated with the grant.
   *
   * Requirements:
   *
   * - The caller must be the current grant manager.
   * - The index must be within the bounds of the external links array.
   *
   * Emits an {ExternalLinkRemoved} event.
   *
   * @param grantId The unique identifier of the grant.
   * @param index The index of the external link to be removed.
   */
  function removeExternalLink(bytes32 grantId, uint256 index) external;

  /**
   * @dev Retrieves details of a specific grant by its ID
   * @param grantId The unique identifier of the grant
   * @return The `Grant` struct containing id, chainid, and community label
   */
  function getGrant(bytes32 grantId) external view returns (Grant memory);

  /**
   * @dev Retrieves the current grant manager for a specific grant
   * @param grantId The unique identifier of the grant
   * @return The address of the grant manager
   */
  function getGrantManager(bytes32 grantId) external view returns (address);

  /**
   * @dev Retrieves the list of grantees associated with a specific grant
   * @param grantId The unique identifier of the grant
   * @return An array of addresses representing the grantees
   */
  function getGrantees(
    bytes32 grantId
  ) external view returns (address[] memory);

  /**
   * @dev Retrieves the start date and list of milestone dates for a specific grant
   * @param grantId The unique identifier of the grant
   * @return The start date and an array of milestone dates
   */
  function getMilestonesDates(
    bytes32 grantId
  ) external view returns (uint256, uint256[] memory);

  /**
   * @dev Retrieves the disbursement details for a specific milestone in a grant
   * @param grantId The unique identifier of the grant
   * @param milestoneDate The date of the milestone for which disbursement details are requested
   * @return The `Disbursements` struct containing the token address, funding amount, and disbursement status
   */
  function getDisbursement(
    bytes32 grantId,
    uint256 milestoneDate
  ) external view returns (Disbursements memory);

  /**
   * @dev Retrieves the list of external links associated with a specific grant
   * @param grantId The unique identifier of the grant
   * @return An array of strings representing the external links
   */
  function getExternalLinks(
    bytes32 grantId
  ) external view returns (string[] memory);
}

Additional Considerations

Efficient data management through field separation

The contract separates data into categories such as identifying information (id and chainid), grant details (community, for example), and funding information (milestones and disbursements). This design makes efficient use of blockchain storage.

Basic identifying information such as id, chainid, and community is treated as fixed data that cannot be changed after registration. This preserves the consistency of basic grant information and makes it easier to reference across different systems and ecosystems. Information that changes as a grant progresses, such as the addition of milestones or changes to recipients, is stored in mutable fields and can be updated. This separation maintains grant transparency while allowing necessary changes.

Modular disbursement management

ERC7794 does not require grant disbursements to be processed onchain. In addition to transferring tokens directly within the contract, funding can be managed offchain through external links.

Individual projects can therefore select an appropriate method rather than requiring every grant program to distribute funds in the same way. For example, a program could integrate bank transfers or a funding distribution system managed by a centralized organization. Projects that distribute funds entirely onchain can instead implement fund transfers within the contract.

This flexibility accommodates grant programs of different scales and types and can improve compatibility with blockchains beyond Ethereum. Even when funds are managed offchain, grant progress and disbursement status can be recorded on the contract, maintaining transparency across the ecosystem.

Team-based grant management

The contract adopts a team-based structure in which grant recipients are represented by multiple addresses. Addresses registered as recipients are managed using EnumerableSet. This enables gas-efficient lookup, addition, and removal of grant recipients.

Team membership can also change as a grant progresses. For example, new members can be added and members whose roles have ended can be removed, allowing the grant team to be managed dynamically. This flexibility in team composition supports grant management that adapts to a project's circumstances.

The mechanism is also suitable for integration with contribution tracking and reputation systems. For example, contributions by members who received grants can be recorded and used in the evaluation of future grant applications. Greater transparency makes it easier to assess the effectiveness of grants and encourages their proper administration.

Scalable and efficient design

The contract aims to be more than a grant management system: it is designed as a scalable mechanism for long-term use. It takes transparency, modularity, and gas cost optimization into account to accommodate a variety of grant program requirements.

The design allows the system to adapt to new forms of grants in the future without requiring a complete overhaul. Standardized data makes grant evaluation and analysis easier and helps visualize the flow of funding across the ecosystem.

Reference Implementation

js
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

import { IGrantRegistry } from "./IGrantRegistry.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

contract GrantRegistry is IGrantRegistry {
  using EnumerableSet for EnumerableSet.AddressSet;
  using EnumerableSet for EnumerableSet.UintSet;

  /**
   * @dev Mapping to store the details of each grant, keyed by its unique grantId.
   */
  mapping(bytes32 => Grant) private _grants;

  /**
   * @dev Stores information about the participants in each grant (manager and grantees), keyed by the grantId.
   * This mapping allows tracking of the grant manager and the associated grantees for each grant.
   */
  mapping(bytes32 => Participants) private _participants;

  /**
   * @dev Stores milestone-related data for each grant, keyed by the grantId.
   * This includes the start date, milestone dates, and disbursements related to each milestone.
   */
  mapping(bytes32 => Milestones) private _milestones;

  /**
   * @dev Stores external links related to each grant, such as proposal URLs or related documentation, keyed by grantId.
   * External links provide references to off-chain information about the grant.
   */
  mapping(bytes32 => string[]) private _externalLinks;

  /**
   * @dev See {IGrantRegistry-registerGrant}.
   */
  function registerGrant(
    uint256 id,
    uint256 chainid,
    string memory community,
    address grantManager
  ) external returns (bytes32) {
    bytes32 grantId = keccak256(
      abi.encodePacked(id, chainid, community, block.timestamp)
    );

    if (grantManager == address(0)) revert InvalidGrantManager();
    if (bytes(community).length == 0) revert InvalidCommunityNameLength();
    if (bytes(_grants[grantId].community).length > 0)
      revert GrantAlreadyRegistered();

    _grants[grantId] = Grant(id, chainid, community);
    _participants[grantId].grantManager = grantManager;

    emit GrantRegistered(grantId, id, chainid, community, grantManager);
    return grantId;
  }

  /**
   * @dev See {IGrantRegistry-transferOwnership}.
   */
  function transferOwnership(
    bytes32 grantId,
    address newGrantManager
  ) external {
    _requireManager(grantId);
    if (newGrantManager == address(0)) revert InvalidGrantManager();
    _participants[grantId].grantManager = newGrantManager;
    emit OwnershipTransferred(grantId, newGrantManager);
  }

  /**
   * @dev See {IGrantRegistry-addGrantee}.
   */
  function addGrantee(bytes32 grantId, address grantee) external {
    _requireManager(grantId);
    if (grantee == address(0)) revert InvalidGrantManager();
    bool success = _participants[grantId].grantees.add(grantee);
    if (!success) revert GranteeAlreadyAdded();
    emit GranteeAdded(grantId, grantee);
  }

  /**
   * @dev See {IGrantRegistry-removeGrantee}.
   */
  function removeGrantee(bytes32 grantId, address grantee) external {
    _requireManager(grantId);
    bool success = _participants[grantId].grantees.remove(grantee);
    if (!success) revert GranteeNotFound();
    emit GranteeRemoved(grantId, grantee);
  }

  /**
   * @dev See {IGrantRegistry-setStartDate}.
   */
  function setStartDate(bytes32 grantId, uint256 startDate) external {
    _requireManager(grantId);
    _milestones[grantId].startDate = startDate;
    emit StartDateSet(grantId, startDate);
  }

  /**
   * @dev See {IGrantRegistry-addMilestoneDate}.
   */
  function addMilestoneDate(bytes32 grantId, uint256 milestoneDate) external {
    _requireManager(grantId);
    bool success = _milestones[grantId].milestonesDates.add(milestoneDate);
    if (!success) revert MilestoneDateAlreadyAdded();
    emit MilestoneDateAdded(grantId, milestoneDate);
  }

  /**
   * @dev See {IGrantRegistry-removeMilestoneDate}.
   */
  function removeMilestoneDate(
    bytes32 grantId,
    uint256 milestoneDate
  ) external {
    _requireManager(grantId);
    bool success = _milestones[grantId].milestonesDates.remove(milestoneDate);
    if (!success) revert MilestoneDateNotFound();
    emit MilestoneDateRemoved(grantId, milestoneDate);
  }

  /**
   * @dev See {IGrantRegistry-addDisbursement}.
   */
  function addDisbursement(
    bytes32 grantId,
    uint256 milestoneDate,
    address fundingToken,
    uint256 fundingAmount
  ) external {
    _requireManager(grantId);
    _requireMilestoneDate(grantId, milestoneDate);
    _milestones[grantId].disbursements[milestoneDate] = Disbursements(
      fundingToken,
      fundingAmount,
      false
    );
    emit DisbursementAdded(grantId, milestoneDate, fundingToken, fundingAmount);
  }

  /**
   * @dev See {IGrantRegistry-removeDisbursement}.
   */
  function removeDisbursement(bytes32 grantId, uint256 milestoneDate) external {
    _requireManager(grantId);
    _requireMilestoneDate(grantId, milestoneDate);
    delete _milestones[grantId].disbursements[milestoneDate];
    emit DisbursementRemoved(grantId, milestoneDate);
  }

  /**
   * @dev See {IGrantRegistry-setDisbursementStatus}.
   */
  function setDisbursementStatus(
    bytes32 grantId,
    uint256 milestoneDate,
    bool isDisbursed
  ) external {
    _requireManager(grantId);
    _requireMilestoneDate(grantId, milestoneDate);
    _milestones[grantId].disbursements[milestoneDate].isDisbursed = isDisbursed;
    emit DisbursementMade(grantId, milestoneDate, isDisbursed);
  }

  /**
   * @dev See {IGrantRegistry-addExternalLink}.
   */
  function addExternalLink(bytes32 grantId, string memory link) external {
    _requireManager(grantId);
    if (bytes(link).length == 0) revert InvalidExternalLink();
    _externalLinks[grantId].push(link);
    emit ExternalLinkAdded(grantId, link);
  }

  /**
   * @dev See {IGrantRegistry-removeExternalLink}.
   */
  function removeExternalLink(bytes32 grantId, uint256 index) external {
    _requireManager(grantId);
    if (index >= _externalLinks[grantId].length) revert InvalidIndex();
    string memory link = _externalLinks[grantId][index];
    _externalLinks[grantId][index] = _externalLinks[grantId][
      _externalLinks[grantId].length - 1
    ];
    _externalLinks[grantId].pop();
    emit ExternalLinkRemoved(grantId, link);
  }

  /**
   * @dev Ensures that the caller is the grant manager for the given grantId.
   * Reverts with `InvalidGrantManager` if the caller is not the grant manager.
   * @param grantId The unique identifier of the grant being checked.
   */
  function _requireManager(bytes32 grantId) internal view {
    if (msg.sender != _participants[grantId].grantManager)
      revert InvalidGrantManager();
  }

  /**
   * @dev Ensures that the milestone date is present in the grant.
   * Reverts with `MilestoneDateNotFound` if the milestone date is not present.
   * @param grantId The unique identifier of the grant being checked.
   * @param milestoneDate The milestone date being checked.
   */
  function _requireMilestoneDate(
    bytes32 grantId,
    uint256 milestoneDate
  ) internal view {
    if (!_milestones[grantId].milestonesDates.contains(milestoneDate))
      revert MilestoneDateNotFound();
  }

  /**
   * @dev See {IGrantRegistry-getGrant}.
   */
  function getGrant(bytes32 grantId) external view returns (Grant memory) {
    return _grants[grantId];
  }

  /**
   * @dev See {IGrantRegistry-getGrantManager}.
   */
  function getGrantManager(bytes32 grantId) external view returns (address) {
    return _participants[grantId].grantManager;
  }

  /**
   * @dev See {IGrantRegistry-getGrantees}.
   */
  function getGrantees(
    bytes32 grantId
  ) external view returns (address[] memory) {
    return _participants[grantId].grantees.values();
  }

  /**
   * @dev See {IGrantRegistry-getMilestonesDates}.
   */
  function getMilestonesDates(
    bytes32 grantId
  ) external view returns (uint256, uint256[] memory) {
    return (
      _milestones[grantId].startDate,
      _milestones[grantId].milestonesDates.values()
    );
  }

  /**
   * @dev See {IGrantRegistry-getDisbursement}.
   */
  function getDisbursement(
    bytes32 grantId,
    uint256 milestoneDate
  ) external view returns (Disbursements memory) {
    return _milestones[grantId].disbursements[milestoneDate];
  }

  /**
   * @dev See {IGrantRegistry-getExternalLinks}.
   */
  function getExternalLinks(
    bytes32 grantId
  ) external view returns (string[] memory) {
    return _externalLinks[grantId];
  }
}

Citation

Guilherme Neves (@0xneves), "ERC-7794: Grant Registry [DRAFT]," Ethereum Improvement Proposals, no. 7794, October 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7794.

Conclusion

This article covered ERC7794, which proposes a mechanism for centrally managing and tracking grants across multiple blockchains.

If you have any questions, feel free to reach out via direct message on Twitter.

Twitter @cardene777