Home

Get UMA updates straight to your inbox

May 23, 2023
6 min read

How to use The Graph to query UMA’s optimistic oracle

Tldr; The Graph is a critical piece of Web3 infrastructure, serving as a decentralized query layer for blockchain data. As UMA has a subgraph, anyone can run queries to search for useful data related to the optimistic oracle.

Key takeaways:
  • The Graph is a data query engine that supports UMA and other Web3 projects.

  • UMA subgraph users can find data related to the optimistic oracle that isn’t easily accessible elsewhere.

  • The Graph shares useful data while maintaining core crypto principles like decentralization, transparency, and immutability.

Decentralized data query with The Graph

The Graph is one of Web3’s most vital projects.

Built to make blockchain data more accessible, the infrastructure project helps power many Web3 applications through its open-source indexing and query protocol. UMA is one of many Web3 projects that uses The Graph’s subgraphs. UMA’s oracle dApp provides accurate, up-to-date information because it pulls data from the subgraph.

But subgraphs are not just useful to applications. Anyone can run queries through The Graph to access data related to the optimistic oracle. While our frontend provides useful information, querying UMA’s subgraph offers an alternative way to access data related to the oracle. UMA’s subgraph runs independently from UMA. Running a query through it maintains decentralization, and any data related to the protocol’s contracts is immutable. This feature explores some of the ways users can explore UMA’s subgraph to learn more about the oracle.

What queries can you run through UMA’s subgraph?

UMA’s subgraph is transparent and available for anyone to browse. You can find it via The Graph’s hosted service at this link. There are many different queries you can run via UMA’s subgraph; below are just a few examples.

Resolved price requests
{
  priceRequests(
    where: { isResolved: true }
    orderBy: resolvedPriceRequestIndex
    orderDirection: desc
    first: 5
  ) {
    price
    time
    resolvedPriceRequestIndex
    isGovernance
    rollCount
    latestRound {
      totalVotesRevealed
      groups {
        price
        totalVoteAmount
      }
    }
  }
}

This query retrieves information about the latest resolved price requests in the UMA VotingV2 system. The different components of this query are as follows:

priceRequests: The main field indicating that we want to fetch data about price requests.

where: { isResolved: true }: This parameter filters the results so only resolved price requests are included.

orderBy: resolvedPriceRequestIndex: This parameter indicates that the results should be listed in ascending order based on the resolved price request index.

orderDirection: desc: This parameter indicates that the results should be listed in descending order with the latest price requests appearing first.

first: 5: This parameter limits the number of results to the top 5 resolved price requests.

Within the priceRequests field, the following subfields are specified:

price: The resolved price of the price request.

time: The timestamp from when the price request was resolved.

resolvedPriceRequestIndex: The index of the resolved price request.

isGovernance: A Boolean value (“true” or “false”) indicating whether the price request is a governance vote.

rollCount: The number of times the vote for this price request has rolled. Votes roll if they do not reach 50% consensus, though this is rare.

latestRound: This subfield provides information about the latest round for the price request.

totalVotesRevealed: The total number of votes revealed for this round.

groups: An array of objects representing different groups of votes.

price: The price associated with the group of votes.

totalVoteAmount: The total vote amount received for that particular price.

You can execute this query to get crucial information about the latest resolved price requests in the UMA VotingV2 system. Data on resolved prices and variables such as their timestamps, resolved indexes, governance status, and vote distribution can be used to analyze voting patterns and consensus outcomes. This can offer valuable insights into the oracle’s overall performance.

When we execute this query, we can see that there was one rolled vote across the five requests.

Top stakers
{
  users(first: 5, orderBy: voterStake, orderDirection: desc) {
    id
    address
    annualPercentageReturn
    annualReturn
    countNoVotes
    countWrongVotes
    countCorrectVotes
    voterStake
    cumulativeSlash
  }
}

This query retrieves information about the biggest stakers in the UMA VotingV2 system. The different components of this query are as follows:

users: The main field indicating that we want to fetch data about users.

first: 5: This parameter limits the number of results to five stakers.

orderBy: voterStake: This parameter limits the list by the number of tokens they have staked.

orderDirection: desc: This parameter lists the users by token staked in descending order.

Within the users field, the following subfields are specified:

id: The user’s unique identifier.

address: The user’s Ethereum address.

annualPercentageReturn: The annual percentage return (APR) the user can earn by staking $UMA.

annualReturn: The user’s annual return in $UMA tokens.

countNoVotes: The number of times the user has not voted on a dispute.

countWrongVotes: The number of times the user has voted incorrectly on a dispute.

countCorrectVotes: The number of times the user has voted correctly on a dispute.

voterStake: The amount of $UMA tokens the user has staked to participate in voting.

cumulativeSlash: The cumulative number of $UMA tokens the user has had slashed as a penalty based on their participation.

You can execute this query to get insights into the top stakers in the UMA VotingV2 system. Data on users and variables such as their unique identifiers, addresses, annual returns, and voting statistics can be used to analyze how the top tokenholders engage with the UMA VotingV2 system. This is useful for identifying trends among influential users and determining the effectiveness of UMA’s governance mechanisms.

When we executed this query, we could see that the top user had staked 6,226,601 $UMA at the time of execution, and they’d had 44,308 $UMA slashed due to missing eight of 20 votes.

A query showing the top five $UMA stakers (Source: The Graph)
A query showing the top five $UMA stakers (Source: The Graph)
Global statistics
{
  globals {
    id
    userAddresses
    cumulativeStake
    emissionRate
    annualPercentageReturn
    annualVotingTokenEmission
    countCorrectVotes
    countNoVotes
    countWrongVotes
  }
}

This query retrieves information about the global statistics in the UMA VotingV2 system. The different components of this query are as follows:

globals: The main field indicating that we want to fetch global information.

Within the globals field, the following subfields are specified:

id: The unique identifier of the global statistics.

userAddresses: All of the user addresses staking $UMA tokens in the VotingV2 contracts.

cumulativeStake: The cumulative amount of $UMA tokens staked across all users in the voting system.

emissionRate: The emission rate of voting tokens in the system.

annualPercentageReturn: The annual percentage return (APR) users can earn by staking $UMA.

annualVotingTokenEmission: The number of $UMA tokens emitted annually in the system.

countCorrectVotes: The total number of correct votes across all users.

countNoVotes: The total number of count no votes across all users.

countWrongVotes: The total number of incorrect votes across all users.

You can execute this query to get comprehensive information about the UMA VotingV2 system. Data on global statistics and variables such as the number of tokens staked, the number of vote counts, and the number of tokens emitted can be used to ascertain the health and performance of the system. This is useful for evaluating the effectiveness of the governance mechanisms, monitoring important variables like token emissions, and identifying trends or anomalies in the system.

When we executed this query, we can see that there were 21,255,549 $UMA tokens staked at the time of execution, the emission rate was 0.18, the APR was 26.7%, and more.

Getting started with UMA’s subgraph

To run a query via UMA’s subgraph, follow the below steps.

1. Head to UMA’s subgraph here.

2. Delete the default text and input your query in the left-hand field.

3. Press the “Execute query” icon.

UMA’s subgraph lets anyone independently find data and learn more about the voter system.

Querying UMA’s subgraph is best suited to coders with an understanding of the GraphQL query language. However, the UMA subgraph is open for anyone to access data on UMA for themselves.

You can visit our docs to learn more, and explore UMA’s subgraph schema via our Github page.

If you want to access data related to the oracle but are unsure where to start, we’d love to hear from you. DM us on Twitter or join the UMA Discord server for more details.

Finally, if you’re interested in partnering with UMA, get in touch with us here.

This piece is a collaborative effort between @dreamsofdefi, Editorial Contributor at Risk Labs and Pablo Maldondo, Smart Contract Engineer at Risk Labs.

Related Articles