✨Plugins
What is a ONCE Plugin?
A ONCE plugin is smart contract functionality that can be installed or uninstalled on a ONCE contract even after deployment. This ability to update the contract at any time—including post-deployment—using plugins makes ONCE contracts future-proof and infinitely extensible, serving the evolving needs of any project. Plugins are the core mechanism that empowers ONCE contracts, providing them with their functionality and adaptability.
The power of ONCE Protocol grows exponentially as the plugin ecosystem grows. ONCE Protocol is designed with an incentive mechanism outlined in our tokenomics to fund and accelerate the development of plugins to eventually serve all of the potential contract needs that power robust dapps.
How do ONCE Plugins actually work (Talk technical to me)
The ONCE Plugin system takes inspiration from the Diamond Proxy Pattern (EIP-2535). Using a similar proxy pattern, the core ONCE contract is a proxy contract that stores a mapping of function selectors to implementation contract addresses. Each Plugin is an implementation contract that is called via delegatecall from the ONCE contract.
There are two contract interfaces that Plugins can adhere to: IONCEPlugin and IONCEPluginMod.
IONCEPlugin
Most ONCE Plugins adhere to the IONCEPlugin interface. The IONCEPlugin interface enforces the getFunctionSelectors
method which returns a list of function selectors to be installed or uninstalled for the plugin. The IONCEPlugin interface also enforces the getSingletonAddress
method which returns the implementation contract address. Most of the time this implementation address is the address of the plugin itself, but in some cases the plugin may return a different implementation address. Plugins that are created as a means to integrate other contracts into the ONCE ecosystem will typically return a separate implementation address. The ONCE Gnosis Safe plugin is a good example of this.
IONCEPluginMod
Some plugins may need to adjust the functionality of other related plugins. In this case the plugin should implement the IONCEPluginMod interface. Plugins can leverage a middleware or modifier pattern to allow other related plugins to modify their functionality. A great example of this is the relationship between the ERC721 and ERC721BalanceLimit plugins. After creating a ONCE and installing the ERC721 plugin, one can install the ERC721BalanceLimit plugin which has an _update modifier function. This function modifies the corresponding function on the ERC721 plugin to enforce a given balance limit.
Contract & Plugin Storage
ONCE leverages an unstructured storage pattern similar to the Diamond Storage pattern outlined in EIP-2535 to avoid collisions between the storage across multiple plugins.
The core ONCE contract storage focuses on the mapping of function selectors to implementation plugin addresses as well as the access control mappings while plugins are responsible for assigning an arbitrary slot for their own storage using the diamond storage pattern.
Last updated