Custom Rules

Custom rules in Salus are designed to give you the ability to write more complicated alerting pipelines that depends on multiple conditions being true at the same time. At the moment custom rules can use storage slot values and ERC20 token balances of a single contract on a single chain. We're working towards offering custom rules that can run across multiple contracts and multiple chains in a single rule. Please let us know if this is something you'd find useful!

How to write custom rules

Under the hood, Salus custom rules are based on https://jsonlogic.com/. We highly recommend checking out the documentation on their site if you want to be able to harness the full capability of custom rules.

The key component in Salus custom rules are the variables referenced in your rules. Each rule must have at least 1 on-chain variable referenced, and each variable has the format storage-[X] or erc20-[X] (e.g. storage-0 or erc20-1). When creating a custom rule you'll be able to define which storage slot or token address the respective variable corresponds to.

Below we'll talk through a few examples of custom rules that could be useful.

Verifying multiple storage slots are within expected value range

In this example we check whether the value at storage-0 is less than 50 and the value at storage-1 is less than 100. If both of these conditions are true, then Salus will throw an alert.

{"and": [
    {"<": [{"var": "storage-0"}, 50]},
    {"<": [{"var": "storage-1"}, 100]}
]}      

Verify if the balance of USDC goes lower than expected whilst the contract is not in a paused state

Imagine a case where you want to pause your smart contract to perform a migration of tokens to another contract. In this scenario your USDC balance will decrease significantly, throwing an alert with most existing alerting tools out there. With Salus, you can use a custom rule to avoid throwing a false positive alert in this scenario, but still be informed of any unexpected token drops.

erc20-0 corresponds to the USDC token address and storage-0 corresponds to the storage slot containing the pause state. These can both be specified when setting up the custom rule on the Salus app.

{"and": [
    {"<": [{"var": "erc20-0"}, 1000000]},
    {"!==": [{"var": "storage-0"}, 1]}
]}

Last updated