A “How-To” for Blockchain Data Analysis: Unveiling Polymarket Insights and Dune Analytics Dashboard

Austin W.
12 min readJan 25, 2024

--

Please see the dashboard/visualizations created by the author on Dune Analytics here (“Polymarket Analysis”). This is referenced throughout the article.

Introduction

This article outlines my data analysis exploration into the day-to-day inner workings of Polymarket. In the dynamic landscape of Web3 technologies, my journey into decentralized prediction markets (DPMs) led me to the doorstep of Polymarket — an intriguing protocol in the space. I share my journey of learning Polymarket’s smart contracts in order to 1. understand & analyze its transaction flow, and 2. gain insights into the protocol’s key metrics. In this journey I use tools such as PolygonScan, Dune Analytics, and GitHub to execute my analysis and share key Polymarket metrics, including bets made per month (conditional tokens bought/sold), bet market monthly payouts, total betting markets (distinct markets settled), and more. These insights can be seen in my dashboard on Dune Analytics, “Polymarket Analysis”.

To kickstart this venture, I scoured the Web3 landscape, seeking an industry ripe with challenges and potential. The DPM sector specifically piqued my interest, with its intersection of finance, technology, and risk. To choose a protocol for my analysis, I reviewed the top DPM protocols on DefiLlama based on Total Value Locked (TVL). Also, I scrutinized their whitepapers to determine if any of the protocols had a unique value proposition for their users. After a thorough examination I was able to pinpoint Polymarket as the subject of my analysis, based on its high wallet address activity and positive value proposition relative to other DPM protocols (i.e. ability to create new markets, strong tokenomics, etc.).

“Prediction Market” category on DefiLlama.com (Jan. 2024)

Choosing Polymarket marked the beginning of a meticulous process. I embarked on a journey that involved deciphering Polygon blockchain data on PolygonScan and grasping the fundamental principles governing the markets it facilitated. Immersing myself in Polymarket’s whitepapers and documentation laid the groundwork for a comprehensive analysis.

But this isn’t just a tale of discovery. This article aims to demystify the practical aspects of my self-taught journey — how I navigated the protocol’s intricate structure, extracted meaningful data, and translated it into informative dashboards on Dune Analytics. The subsequent sections will guide you through the steps of my analytical process: from understanding the protocol’s structure to the nitty-gritty of data analysis, concluding with the unveiling of key insights.

Overall, this article can be used as a high-level approach to help members of the Web3 community learn how to conduct data analysis on a Web3 protocol that interests them. Whether you’re a seasoned blockchain expert or a newcomer to the space, the goal is to unravel the complexities of blockchain data analysis, showcasing technical proficiency while fostering a deeper understanding of the subject.

My approach to Data Analysis

1 — Understand the Fundamentals

Starting from square one, I needed to outline an approach. I could have started by viewing others’ analysis on Polymarket (of which there is few), but I realized that I wanted to take a replicable approach that could be applied to other protocols in the future. Especially for lesser known protocols where I would be the first one conducting analysis. This is where I reached out to my network and got great advice from a mentor & a member on the Data team for Maple Finance (Twitter: @fat_mac2). Their advice was to start understanding the fundamentals of a protocol by looking at the protocol’s most granular transactions. Once the flow of funds in a basic transaction is understood, you can aggregate the movement of these funds and build from there.

So, that’s where I started. I asked myself: what is the most basic transaction that can be made on a prediction market? The answer: placing a bet.

In terms of Polymarket, placing a bet is done by buying/selling a conditional outcome token (ERC-1155). In layman’s terms, if I want to bet on “Candidate A becoming President”, then on Polymarket, I buy the “Candidate A will become President” conditional outcome token (ERC-1155) — for a more detailed explanation, see the How it works section in my previous article about DPMs.

In order to understand this transaction, I read the Polymarket Learn pages which had tutorials and other resources to understand the basics of Polymarket. More importantly I read the Polymarket Docs which includes all the smart contract & coding information needed for interacting with Polymarket. The three key pieces of information I learned from these docs were:

  1. In order to place bets on Polymarket, your collateral needs to be in USDC. Only USDC can be deposited on the platform.
  2. There are two types of exchanges that enable bets to be placed, CLOB (Central Limit Order Book) and FPMM (Fixed Product Market Maker).
  3. Outcome tokens of the betting market are governed by Gnosis’ Conditional Token Framework (CTF). Every time a new betting market is made, two conditional outcome tokens are minted (i.e. “YES” and “NO”), if the market is binary. These tokens are ERC-1155 tokens and are backed by USDC collateral.

Once I knew what smart contract addresses I was looking for, I was able to understand the flow of a betting market transaction by reviewing the different Transaction Hashes from betting activity on the Polymarket site.

For example, let’s say I pick the market Bitcoin all time high by Mar 31? Next I scroll down the page to the Activity log in the market and choose our volunteer (thanks JDoe).

Activity log in the “Bitcoin all time high by Mar 31?” market (Jan. 12, 2024)

Next, I click into JDoe’s username to go to their Polymarket page and look at their activity. In the bottom right corner of the below image, there is a hyperlink to the Transaction Hash on PolygonScan.

Polymarket Activity log of JDoe purchase on “Bitcoin all time high by Mar 31?” market (Jan. 12, 2024)

That hyperlink brought me to the below image, which displays all of the information of that transaction on the Polygon blockchain. This is where the magic happens, as we can learn the following information:

  • JDoe’s wallet address
  • Other wallet addresses involved in the transaction
  • Smart contract addresses in the transaction
  • Conditional Token IDs (ERC-1155) in this market
  • Amount of the Conditional Tokens transferred in this transaction
PolygonScan Transaction Hash of JDoe purchase on “Bitcoin all time high by Mar 31?” market

Based on my knowledge of Polymarket’s smart contract addresses, we can infer the following:

  • JDoe bought 227 shares of the “YES” outcome for $50 USDC tokens (22¢ per share)
  • Another wallet address bought 227 shares of the “NO” outcome for $177 USDC tokens (78¢ per share)
  • The CLOB smart contract address sent the total $227 USDC tokens to the Conditional Token Framework smart contract address for token balancing purposes

Once I knew how to break down Polymarket transactions on PolygonScan, I then reviewed all different transaction types (i.e. Buying outcome “YES”, Selling outcome “YES”, Buying outcome “NO”, Selling outcome “NO”) to see how the smart contracts interacted. This included both CLOB and FPMM market types and allowed me to understand what I needed to look for on Dune.

Additionally, I could now validate that any output data I queried on Dune was accurate, as I could verify that the the actual transaction information on PolygonScan matched the resulting data table (from my SQL query).

2 — Query the Fundamental Transactions

Next I went to Dune Analytics to review all of the event log tables they had from Polymarket.

Dune Analytics is a blockchain data tool for crypto analysts and investors. It allows users to query, extract, and visualize data from different public blockchains.

Within the Dune website there are tables called event logs for a wide range of protocols. Smart Contracts emit event logs when certain predefined actions are completed. The structure published in these logs is predefined by the developer of the smart contract, the content is dynamically created during the transaction. Logs are useful for monitoring, alerting and in general keeping track of what happens inside of a smart contract.

Dune Analytics: titles of different Polymarket transaction raw data tables

I reviewed all event log tables that Dune Analytics offered on Polymarket transactions to understand what data they were emitting and determine what value I could extract from them.

This led me to a wide variety of tables where I could query the information for different insights. An example of a table with key Polymarket transactional information is the OrderFilled table for the CTFExchanges (i.e. Conditional Token Framework Exchanges).

Output of OrderFilled table for the CTFExchanges (i.e. Conditional Token Framework Exchanges)

This had info on every bet that had been initiated and settled on the Polymarket CLOB exchange, including the initiator of the transaction (either Buy or Sell side), counterparty (either Buy or Sell side), Conditional Token ID, amount of Conditional Tokens, time of transaction and more.

This was a challenging portion of my journey as I had to determine how the information listed on the event log tables matched up with different transactions on the Polygon blockchain. To understand what was happening, I had to cross-reference transactions from event logs on Dune with transactions from the Polygon blockchain on PolygonScan.

For instance, let’s refer back to JDoe buying 227 shares of the “YES” outcome in the Bitcoin all time high by Mar 31? market. In this case, the initiator of the transaction (JDoe) is Buying a Conditional Token.

I then cross-referenced the JDoe’s transaction hash on the OrderFilled event log table on Dune with the same transaction hash on PolygonScan.

After repeating this process for many transactions, I was able to decipher the following — if the initiator of the transaction is Buying a Conditional Token, the fields from the OrderFilled event log table will display the following:

  • makerAssetId = Null
  • takerAssetId = NotNull (and this indicates what Conditional Token is being bought)
  • makerAmountFilled = how much USDC was spent for those Conditional Tokens
  • takerAmountFilled = how many Conditional Tokens were bought
  • maker = Wallet address of the BUYER
  • taker = Wallet address OR Contract address of the SELLER (this varies)
Query results for Buying a Conditional Token txn on Dune — raw

After cleaning up the field names and token amounts from their raw data, I queried the following table for Buying transactions:

Query results for Buying a Conditional Token txn on Dune — cleaned

From here, the process was ‘rinse and repeat’ for any table I found to possess valuable information. This breakthrough was critical. I knew that once I understood the flow of transactions within the Polymarket smart contracts for one betting market, I could do it for all betting markets. And this isn’t limited to Polymarket, the same thing could be done for other protocols such as Uniswap. Once you are able to trace the transaction flow across smart contracts for something simple (i.e. the WETH-USDC pool), you can do it for any token pair!

Using my knowledge in SQL to query the information from raw data in the event logs was critical for building out my insights. As an example, the query I wrote to build out the above Buying a Conditional Token table can be seen in the image below.

SQL query written to view the Buying a Conditional Token table

In the intricate realm of blockchain data analysis, the journey detailed above took considerable time and effort. Recognizing that each protocol presents its unique challenges, the overarching approach outlined below emerges as a replicable methodology that can be applied across a diverse number of protocols:

  1. Understand the most granular transaction type of a protocol, then
  2. Review event logs of that protocol on a blockchain data tool (i.e. Dune) to connect its recorded data with the information on that protocol’s blockchain explorer (i.e. Etherscan, PolygonScan, Solscan, etc.)

While the path may be arduous, the reliability and versatility of this approach have been affirmed not only through personal experience but also through the endorsement of professionals within the industry. It is my hope that fellow data analysts find value and applicability in this method, fostering a shared understanding and proficiency within the dynamic landscape of blockchain analysis.

Results — Insights from Polymarket’s activity

Having navigated the meandering path of Polymarket’s blockchain data and armed with a comprehensive understanding of its inner workings, it’s time to shed light on the valuable insights gleaned from this analysis. Beyond the technical intricacies, below outlines the tangible outcomes, all while leveraging a user-friendly dashboard I crafted on Dune Analytics.

The main takeaways I gathered from my analysis of Polymarket’s transaction activity are outlined below:

  1. Significant spikes in Order Book (CLOB) market activity in March 2023 & October 2023 — this could indicate either increased DPM activity OR an increase in activity proportionally of CLOB markets over FPMMs (Market Maker markets) on Polymarket.
  2. More Buying of conditional tokens than Selling — overall market activity has a higher ratio of buying conditional tokens than selling them. This ratio makes sense as users want to get in on the action by placing bets and subsequently wait for the result to see if they win. Users’ only motivation to sell is if they see an immediate gain in their outcome’s value and want to cash in early, or see potential losses and want to cash out before the market settles and they lose their bet entirely.
  3. Amount Paid for tokens is always less than total # of tokens — the total $USD amount when buying or selling Conditional Tokens will always be less than the total number of tokens transacted. This makes sense as the maximum value a token can be is 100¢. My dashboard confirms that this portion of Polymarket’s tokenomics is working properly.
  4. Drop in activity after TerraUSD (UST) depegging — a lot of liquidity moved away from Polymarket after the depegging of the algorithmic stablecoin, TerraUSD (UST) and the collapse of the Terra network. This was mirrored by the entire DeFi ecosystem as the vast majority of liquidity fled at this time.
  5. Since 2022, average amount of payout per market settled has reduced — after the Terra network collapse, it was expected to see a significant reduction in activity on Polymarket, but what I found extremely interesting is that, proportionally, the reduction of # betting markets settled (indicated by the Monthly Payouts dashboard) was less than the reduction of liquidity (indicated by the Monthly Payout Amount (USD) dashboard).
Two visualizations from my Polymarket Analysis dashboard on Dune Analytics

Further to point #5, this indicates that there is less money being paid out on average per betting market settled, and ultimately indicates that there is less liquidity (on average) circulating in Polymarket . This is key knowledge as a DPM protocol is only as good as its liquidity. When there is more liquidity in a betting market, the betting lines become less volatile when large bets are made.

DPM protocols want to ensure that volatility in betting lines is reduced as much as possible to mitigate manipulation of the betting lines in a market from whales making one big bet.

As this is the case, I’m sure that increasing liquidity in the protocol (possibly through incentivization) will be a focus for Polymarket moving forward.

Conclusion

In the labyrinth of Polymarket’s intricate blockchain data, we’ve journeyed from understanding the granular transaction types to peeling back the layers of event log tables. The path has been arduous, but the rewards lie in the insights harvested from this analytical expedition.

Beyond the technicalities, the results are captured in a user-friendly Dune Analytics dashboard, revealing significant spikes in CLOB market activity, an intriguing dominance of buying over selling in conditional tokens, and the nuanced dynamics of token payouts. Notably, a drop in activity post-TerraUSD depegging underscores the interconnectedness of Polymarket with broader DeFi shifts.

As we dissected the data, a compelling trend emerged — a reduction in the average payout per settled market since 2022. This signals a proportional decrease in the liquidity circulating within Polymarket, shedding light on the importance of liquidity for a decentralized prediction market’s stability.

This journey isn’t just about Polymarket; it’s a blueprint for unraveling the complexities of any Web3 protocol. The methodology — understand the granular, review event logs — proves versatile and replicable. My hope is that fellow data analysts find value and camaraderie in this shared exploration, contributing to a richer understanding within the dynamic landscape of blockchain analysis.

--

--