Initialize a Tracker
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. The added rule limits total volume to 1 billion tokens. This rule by itself would simply prevent further trading once that limit is reached. We will add the additional trackers and rules create a fully functioning policy as the guide continues below.policy.json
Track User Trade Count
Next, we’ll add a mapped tracker, which is similar to a tracker, but allows storing a map of values instead of a single value. This rule condition ensures that the sender has not exceeded 10 transactions.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 as 1 billion in trading volume is reached the token will no longer be transferrable. Fixing this requires resetting theTradingVolume 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
You may have noticed the
GV:BLOCK_TIMESTAMP variable above. The Rules Engine enables you to
access the block data with the GV prefix. See the global variables
for more info.