Initialize a Tracker
As outlined in the policy configuration guide, you define your trackers in thepolicy.json file for your project. Below is an example policy to illustrate the examples that will follow.
policy.json
- Trackers can be used as input values in rule expressions.
- Trackers can be updated as effects of rules.
Usage in Rules
First, we need to add at least one rule to the policy that will use the named trackers.Tracker
This rule condition ensures that the total volume so far and the newamount does not exceed 1 billion tokens.
policy.json
Mapped Tracker
This rule condition ensures that the sender has not exceeded 10 transactions.policy.json
Tracker Update Effects
As of now, this rule will always succeed because the tracker value is never updated. Below we add apositiveEffect that updates the tracker value whenever a transfer call is successful.
Tracker
policy.json
Mapped Tracker
policy.json
Taking it Further
The rule defined thus far is a good start, but needs additional configuration to achieve the desired outcome. First, as soon as1_000_000_000 in trading volume is reached the token will no longer be transferrable. Fixing this will requires resetting the TradingVolume tracker when the defined duration is reached. To do this we need another tracker to record the timestamp and mark the beginning of a rolling 24 hour period. Then we test for that condition in a new rule and reset the tracker values when the condition is true.
policy.json
The new rule above is leveraging the
block.timestamp directly within the rule condition. This is
not supported in the current version of the Rules Engine, but is anticipated. In the meantime,
you’d need to directly pass the timestamp value as an extra argument to the modifier added to the
_update function.Find more info about how to do this in the contract integration guide.