Skip to main content

Monitoring Network Validators Exits

In this tutorial, we’ll show you how to set up a Tenderly Web3 Action to monitor Lido validator exit requests and send notifications via Telegram. This project demonstrates how to use Web3 Actions to interact with smart contracts and external APIs to create a custom notification system. Use this Github project template to set up your own monitoring of Lido validator exit requests:

Validator monitoring Web3 Action template

Project Overview

The purpose of this project is to set up a system that monitors Lido validator exit requests and sends notifications when specific conditions are met. Here’s a quick breakdown of the project’s flow:
  1. Subscribe to relevant on-chain events: The Web3 Action listens for ValidatorExitRequest events from the Lido contract on the Ethereum mainnet.
  2. Decode event using Tenderly API: When an event is detected, it retrieves the transaction details using the Tenderly API.
  3. Filter for specific events of interest: The ValidatorExitRequest event is evaluated further by checking if the stakingModuleId is 1 and the nodeOperatorId is 14.
  4. Respond: If ValidatorExitRequest of interest has happened, the Web3 Action sends a notification to the specified Telegram channel with details about the validator exit request.

Prerequisites

Before you begin, make sure you have the following:
  • Tenderly CLI installed
  • Node.js (v20 currently supported)
  • npm
  • A Telegram bot token and channel ID
  • A Tenderly account and project

Setup

Let’s go through the steps to set up your Lido Validator Exit Notification system:
1
Clone the Repository
2
First, clone the project repository and navigate to the project directory:
3
git clone https://github.com/Tenderly/tenderly-lido-validator-monitoring-solution
cd tenderly-lido-validator-monitoring-solution
4
Install Dependencies
5
Install the required npm packages:
6
npm install
7
Configure Tenderly Project
8
Set up your Tenderly project by following these steps:
9
  • Log in to your Tenderly account
  • Create a new project or use an existing one
  • Note down your Account Name and Project Slug
  • 10
    Configure tenderly.yaml
    11
    Update the tenderly.yaml file with your Tenderly project information:
    12
    account_id: "<YOUR_ACCOUNT_ID>"
    actions:
      <YOUR_ACCOUNT_ID>/<YOUR_PROJECT_SLUG>:
        runtime: v2
        sources: actions
        specs:
          action_name:
            description: Get a notification when condition matches on Lido tx
            function: lidoEvents:subscribeToLidoValidatorExitRequestFn
            execution_type: parallel
            trigger:
              type: transaction
              transaction:
                status:
                  - mined
                filters:
                  - network: 1
                    eventEmitted:
                      contract:
                        address: 0x0de4ea0184c2ad0baca7183356aea5b8d5bf5c6e
                      name: ValidatorExitRequest
    project_slug: "<YOUR_PROJECT_SLUG>"
    
    13
    Make sure to replace <YOUR_ACCOUNT_ID> and <YOUR_PROJECT_SLUG> with your actual Tenderly Account Name and Project Slug.
    14
    Add contract address to the project
    15
    In order to be able to deploy action and monitor desired contract, you need to add that contract to the project.
    16
    In this case we want to add 0x0de4ea0184c2ad0baca7183356aea5b8d5bf5c6e.
    17
    Set Up Secrets
    18
    Add the following secrets to your Web3 Actions:
    19
  • BEARER: Your Tenderly API bearer token
  • BOT-TOKEN: Your Telegram bot token
  • CHANNEL-ID: Your Telegram channel ID
  • 20
    To add secrets, go to Web3 Actions inside your project and navigate to the Secrets section.
    21
    Deployment
    22
    To deploy your Web3 Action, use the Tenderly CLI:
    23
    tenderly actions deploy
    
    24
    This command will deploy the action defined in your tenderly.yaml file.

    How it Works

    Let’s break down the main components of the lidoEvents.ts file:
    showLineNumbers
    
    const subscribeToLidoValidatorExitRequestFn = async (
      context: Context,
      transactionEvent: TransactionEvent,
    ) => {
      // Event handling logic here
    };
    
    // Helper functions for API calls and notifications
    
    The subscribeToLidoValidatorExitRequestFn function is the main entry point for our Web3 Action. It handles the following tasks:
    1. Retrieves transaction details using the Tenderly API
    2. Checks if the stakingModuleId is 1 and the nodeOperatorId is 14
    3. If the condition is met, sends a notification to the specified Telegram channel

    Tenderly API for Transaction Trace

    A key part of this Web3 Action is retrieving the transaction trace using the Tenderly API. Here’s the API endpoint used:
    const url = `https://api.tenderly.co/api/v1/public-contract/${network}/trace/${txHash}`;
    
    This API endpoint returns the detailed trace of the transaction, which includes all the logs and events emitted during the transaction execution. Here’s what each part of the URL represents:
    • https://api.tenderly.co/api/v1/public-contract/: The base URL for Tenderly’s public contract API
    • ${network}: The network identifier (e.g., 1 for Ethereum Mainnet)
    • ${txHash}: The hash of the transaction we’re interested in
    The response from this API contains a wealth of information about the transaction, including:
    • All emitted events and their parameters
    • Internal calls made during the transaction
    • State changes that occurred
    In our Web3 Action, we use this trace to find the ValidatorExitRequest event and extract relevant information:
    showLineNumbers
    const validatorExitRequestLog = result.logs.find(
      (log: any) => log.name === "ValidatorExitRequest"
    );
    
    if (validatorExitRequestLog) {
      const stakingModuleId = validatorExitRequestLog.inputs.find(
        (input: any) => input.soltype.name === "stakingModuleId"
      )?.value;
      const nodeOperatorId = validatorExitRequestLog.inputs.find(
        (input: any) => input.soltype.name === "nodeOperatorId"
      )?.value;
      // ... other parameters
    }
    
    This allows us to precisely identify the validator exit requests we’re interested in and extract the necessary information to send our notification.
    Using the Tenderly API for transaction traces provides a powerful way to access detailed information about on-chain events without having to directly interact with the blockchain or set up your own node.

    Customization

    For Lido validator exits, events of interest are recognized by parameters stakingModuleId with value 1, and nodeOperatorId with value of 14. To modify these filtering conditions or add more events to monitor:
    1. Edit the lidoEvents.ts file
    2. Update the condition check in the if statement to match your requirements
    3. Modify the message format or add additional information as needed
    For example, to change the stakingModuleId and nodeOperatorId conditions:
    showLineNumbers
    if (stakingModuleId == 1 && nodeOperatorId == 14) {
      // Your custom logic here
    }
    

    Monitoring and Troubleshooting

    To ensure your Web3 Action is working correctly:
    • Monitor your Web3 Action executions in the Tenderly dashboard
    • Check the Tenderly logs for any error messages or execution details
    • Ensure your Telegram bot has permission to send messages to the specified channel
    This setup is specifically designed to monitor Lido validator exit requests on the Ethereum mainnet.

    Conclusion

    You’ve now set up a custom notification system using Tenderly Web3 Actions to monitor Lido validator exit requests.