Projects
Main concepts
Hooks system

Hooks System

Hooks are functions that are invoked before or after specific actions, such as transfer events. The Nexera Protocol offers a hooks system that enables additional functionality and customization during the transfer and management of ODC tokens as well as their Properties and associated Restrictions. There are two types of hooks: internal and external.

The distinction between these types lies in the fact that internal hooks are implemented in the facets of the Core Diamond and are executed via the low-level method delegateCall(), potentialy updating the storage of the Diamond. On the other hand, external hooks are implemented in external contracts called Property Managers and are executed via the low-level method call().

Another key thing to note is that both internal and external hooks must be registered in the storage of the Core.

Internal Hooks

As already mentioned, internal hooks must be registered for an address and a selector, which MUST be on the Core (the address must be a facet of the Core Diamond). Also, internal hooks must be defined and registered exclusively by the use-case deployer.

There are two types of internal hooks:

  • Hooks related to tokens (ODCs).
  • Hooks related to Restrictions.

Hooks for Tokens (internal)

We have one token-related hook for ODCs: BeforeTokenTransferHook, which triggers before an ODC token transfer event. This hook must call a facet of the diamond.

Hooks for Restrictions (internal)

There are three restriction-related hooks which are triggered when adding, moving, or removing a Restriction.

  1. AddRestrictionHook: Triggers when a new Restriction is added to a Property of an ODC.
  2. RemoveRestrictionHook: Triggers when a Restriction is removed from a Property of an ODC.
  3. MoveRestrictionHook: Triggers when a Restriction is transferred from an ODC to another.

External Hooks

External hooks must be implemented by Property Managers and can call external contracts. They are linked to Properties.

Hooks for Properties (external)

  1. beforePropertyTransferHook: Triggers before the transfer of a Property and can call an external contract.
  2. onTransferConflictHook: Triggered only when the same Property is found on the ODC that receives the Property from the first one.

By leveraging the hooks system, the Nexera Protocol allows for greater flexibility and customization during the transfer and management of ODCs and their Properties, making it possible to implement complex and tailored use cases in the ecosystem.