Adding A New Token Level Rule To The Rule Processor Diamond
Purpose
There are several updates that need to take place in order to add a new token level rule. In this document we’ll be covering the steps required to update the protocol rule processor diamond including: updating the code for the appropriate facets and upgrading the diamond. This document will walk through the process step by step. (We will be using an existing rule, Token Minimum Transaction Size, as our example)
Creating The Rule
Updating Diamond Storage
The first step is to update the diamond storage to account for the new rule. We’ll need to update RuleStoragePositionLib. For our example we would first add the following constant to the top of the contract to define the storage position for our Token Minimum Transaction Size rule:
Next we’ll want to define the storage structure for our rule. For our example we would add the following struct to IRuleStorage:
Finally we’ll want to add a function to retrieve the storage for our rule to RuleStoragePositionLib.sol. For our example we would add the following function:
Facet Updates
The next step is to update the RuleDataFacet contract to include a function that can be used to create an instance of our new rule and register it with the diamond. For our example we would add the following function:
Upgrading Existing Diamonds
Once the above changes have been made to add the new rule, in order to make the rule available we will need to upgrade the existing diamond instance. Step by step instructions on this upgrade are provided in RULE-PROCESSOR-DIAMOND-UPGRADE