Skip to main content

Introduction

This guide shows you how to stream real-time DEX activity from Polygon into your own database. You’ll tap into the most active decentralized exchanges on the network: Uniswap, Quickswap, Balancer V2, Sushi, and Curve. The template captures a range of onchain events including swaps, liquidity changes, and more. By the end, you’ll have a working pipeline that decodes relevant contract event logs and stores structured trade data for analysis or downstream use.

Prerequisites

You’ll need:

What You’ll Build

A pipeline that:
  1. Listens to the majority of Polygon DEX contracts and their events
  2. Decodes them with the event metadata
  3. Streams transformed data into a unified postgres table

Step 1: Add the Transformation Logic

We’ll want to decode and return all events + unified swaps for known DEXs. View the full code here

Step 2: Create the Transformation

Step 3: Create the Database

The contract_address and pool_address represents the swap pool for dex_events and swaps, respectively. The above provides a single, primary key index for each table, but you may find you want other indexes added based on scale and query patterns.

Step 4: Create the Pipeline

Step 5: Test the Stream

Once live, your database should receive events like:
You can test this manually and end-to-end using:

Wrap-Up

You’ve now set up a real-time stream of Polygon DEX events using The Neighborhood. The data you’re receiving is contains events from the most used Polygon DEXs. 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?