Developers
Build an Eigenlayer AVS
Incredible Squaring AVS

Incredible Squaring AVS Example

Introduction

This will guide you through setting up and using EVM event listeners for EigenLayer AVSes, using examples from the Incredible Squaring blueprint implementation (opens in a new tab).

EVM event listeners are crucial for interacting with smart contracts on Ethereum-compatible networks. In the context of EigenLayer and the blueprint macro system, these listeners allow your Gadget to respond to specific events emitted by EigenLayer contracts.

Setting Up EVM Event Listeners

1. Contract Definition

First, define the contract interface using the sol! and load_abi! macros. This generates Rust bindings for your smart contract.

2. Job Definition with Event Handler

Use the #[job] macro to define a function that will handle specific events. Include the event_listener attribute to specify the event details:

3. Event Converter Preprocessor Function

Implement a preprocessor function to convert the event data into the format expected by your job function:

Implementing the Event Listener

1. Set Up the Provider

Create an HTTP provider to connect to the Ethereum network w/ a wallet enabled for transacting:

2. Create the Contract Instances and Event Listeners

Instantiate the contract using the generated bindings:

3. Set up the BlueprintRunner

Use the BlueprintRunner to execute the jobs and background services:

Testing the Incredible Squaring AVS

1. Prerequisites

Before you begin, ensure you have the following installed:

Anvil Docker

2. Installation

Clone this repository:

git clone https://github.com/tangle-network/gadget.git
cd gadget

Install Anvil:

curl -L https://foundry.paradigm.xyz | bash
foundryup

Running the AVS on a Testnet

We have a test for running this AVS Blueprint on a local Anvil Testnet. You can run the test with the following:

RUST_LOG=gadget=trace cargo test --package incredible-squaring-blueprint-eigenlayer test_eigenlayer_incredible_squaring_blueprint -- --nocapture

Best Practices and Considerations

  1. Error Handling: Implement robust error handling in your event listener functions to manage potential failures gracefully.
  2. Asynchronous Operations: Use async/await for operations that may take time, such as network requests or complex computations.
  3. Event Filtering: Consider implementing additional filtering logic in your event converter function if you need to process only specific events based on certain criteria.
  4. State Management: If your Gadget needs to maintain state between events, consider implementing a state management system.
  5. Testing: Implement unit tests for your event handling logic, including the event converter function.
  6. Logging: Use appropriate logging to track the event handling process and aid in debugging.
  7. Gas Considerations: Be aware of the gas costs associated with your on-chain interactions, especially when responding to events with transactions.
  8. Scalability: Design your event handling system to scale with the number of events you expect to process.