Basics

Let's first start with a simple example. The USDC blacklister address. The EOA that can blacklist USDC accounts needs to be able to make onchain transactions to blacklist malicious entities. We want to get an alert whenever its native ETH balance drops below 0.1 ETH, to ensure it has enough gas to make transactions quickly.

use Balance from hexagate;

source blacklister: address = 0x10DF6B6fe66dd319B1f82BaB2d054cbb61cdAD2e;

source balance: integer = Balance {
    address: blacklister
};

source threshold: integer = 10 ** 17; // 1 ETH is 10 ** 18 wei

rule {
    description: "USDC Blacklister balance is $balance, which is below the threshold of $threshold",
    condition: balance >= threshold
};

Let's break this down:


use Balance from hexagate;

Here we are just importing the Balance datasource, which we'll use later.


A source statement is similar to defining variables in other programming languages. Here we're calling this source blacklister, stating that it is an address (the data type), and setting it to be the blacklister address.


We're creating another source called balance, and using the builtin Balance datasource to fetch native ETH balances. The Balance datasource receives an address as parameter, so here we are fetching the balance of the blacklister.


Balances are denominated in wei (smallest unit in Ethereum), which is 10 ** 18 wei. We want the threshold to be 0.1 ETH, which means it should be 10 ** 17 wei.


Every gate files will have at least one rule, which defines what needs to be checked every block. In this case, the condition is balance >= threshold. The description is the message that will appear in the alert when the rule is broken. Notice the usage of $balance and $threshold, which will embed the actual values of these sources into the message.

Notice that the condition is what has to be true every block, and an alert will be generated if for a given block the condition is false.

To summarize, this short gate file (once set up as a monitor on Ethereum Mainnet) will check every block that the ETH balance of the USDC blacklister is >= 0.1ETH, and will create an alert if this is not the case, with a customized alert message.

Last updated