Introduction
In this guide, you’ll build a real-time pipeline to track lending and borrowing activity from Polygon money markets AAVE and Compound V3. By listening to core protocol contracts, you’ll capture events like deposits, borrows, repayments, and liquidations, then decode and stream them directly into your database. By the end, you’ll have a working pipeline that decodes relevant contracts event logs and stores structured trade data for analysis or downstream use.Prerequisites
You’ll need:- A Neighborhood API key. To get access, sign up at accounts.indexing.co or email hello@indexing.co
- curl or Postman
- An active postgres database
What You’ll Build
A pipeline that:- Listens to the majority of Polygon money market contracts and their events
- Decodes them with the event metadata
- Streams transformed data into a unified postgres table
Step 1: Create a Contract Filter
Then create the filter: These are the contract addresses we’ll want to listen to:Step 2: Add the Transformation Logic
We’ll want to decode and return a unified set of in and out flows for known markets. View the full code hereStep 3: Create the Transformation
Step 4: Create the Database
pool_address
represents the liquidity pool that the event is tied to and method
can be used to identify specific events. The above provides a single, primary key index, but you may find you want other indexes added based on scale and query patterns.
Example Queries
Identifying USD volume by liquidity pool within the last hour:Step 5: Create the Pipeline
Step 6: Test the Stream
Once live, your database should receive events like:Wrap-Up
You’ve now set up a real-time stream of Polygon Money Market events using The Neighborhood. The data you’re receiving is contains events from the most used Polygon Money Markets, AAVE and Compound V3. In case you want to add new DEXs we encourage you to reach out to us or adjust the template. Need help or want to go further?- Reach out at indexing.co/get-in-touch
- Or email us at hello@indexing.co