Anyblock Analytics was selected by The Graph Foundation for a Wave 2 grant to develop a tool for the optimization of allocations. On Friday, September 10, 2021, the tool officially entered the beta phase (but still with reduced functionality). In this phase, we are very happy to receive feedback, bug reports, and suggestions for improvement.

Check out the repository for the allocation optimization tooling and get started.

Featured Image Source: Announcing The Graph Foundation

Project Idea

Problem Statement

How can Indexers easily and quickly calculate allocation size, so as to optimize indexing rewards for themselves and their Delegators?

Indexers have a vital role to fulfill in The Graph Network. This role is incentivized by two revenue streams. In one stream, Indexers are rewarded by receiving payments for serving queries in the network (query fee rebates). In the second stream, the 3% annual protocol-wide issuance is distributed to Indexers who index subgraphs in the network, known as Indexing Rewards. See The Graph Documentation for further information.

Quoting the FAQ on The Graph Documentation:

Indexing rewards come from protocol inflation which is set to 3% annual issuance. They are distributed across subgraphs based on the proportion of all curation signals on each, then distributed proportionally to indexers based on their allocated stake on that subgraph. An allocation must be closed with a valid proof of indexing (POI) that meets the standards set by the arbitration charter to be eligible for rewards.

Allocations are therefore a core aspect of The Graph ecosystem for Indexers to earn indexing rewards. Based on the distribution and the amounts of allocations on different subgraphs, the indexing rewards are calculated using this equation:

TheGraph Reward Indexing Equation
One could now calculate the indexing reward manually for each subgraph and distribute its stake accordingly. An alternative to this would be to define a rule that the indexer agent uses to distribute the allocations automatically. For example, one could distribute the stake equally among all subgraphs in the network. However, this might lead to not getting the optimum indexing reward.

Image Source: Discord stake-machine#1984

Solution

Since a manual approach does not yield the optimal rewards, we used the grant to develop a tool that computes the optimal allocation distribution using optimization algorithms. The relevant data for calculating the optimal allocation distribution is fetched using the network subgraph and other data sources, and fed into the linear optimization model. This model then calculates the optimal distribution of allocations on the different subgraphs, taking into account the preferences and parameterizations of the Indexer.

The user of this allocation optimization script can adjust the allocation optimization process according to their wishes through some parameters. The following adjustments can be made:

  • A blacklist can be created. The subgraphs in the blacklist are not considered in the allocation process. The script creates a blacklist using various functions to avoid possible “bot-bait” subgraphs. The script can also blacklist specific subgraph developers, exclude subgraphs with error status or an outdated version, and blacklist subgraphs based on the sync status of the local Indexer database.
  • A predefined subgraph list can be passed. Only these subgraphs should be considered in the allocation process and the stake should be distributed optimally among them.
  • Threshold: With the threshold set, a percentage limit is determined. If this threshold is exceeded, a reallocation is appropriate and the tool creates a script.txt file containing the relevant commands for a reallocation.
  • Slack alerting can be integrated using webhooks. Each execution of the script creates an alert in a defined Slack channel if the threshold for a possible reallocation has been reached.
  • And many more parameters which are described in the documentation of the tooling.

The final product will allow for:

  • Visualization of the optimization process in a web app, which users can interact with to input various parameters such as the amount of stake to be allocated, maximum number of allocations, and maximum number of subgraphs on which to allocate, etc.
  • Visualization of the historic and current rewards from Indexing in the web app
  • Scheduling when such optimization processes should take place while automating the implementation of resulting suggestions.

Impact and Goal

The goal is to provide Indexers with a tool to gain the highest possible return of indexing rewards from their invested stake and to react to changes in the ecosystem in an automated way. The optimization process takes the distribution of allocations and signals into consideration. After every successful optimization, the results for the next optimization will differ from the previous one. It is an ever-changing process of optimization because the relevant variables for the formula change. Every Indexer who would use our allocation optimization script would benefit from it. Manually keeping track of changing circumstances in the ecosystem and distribution would be too time-consuming and cannot scale with the growth of The Graph Network.

This simplifies and optimizes the largest revenue stream of an indexer, making this role more accessible and attractive, therefore helping to further decentralize this part of the ecosystem. All participants would benefit, as their costs decrease, profits would increase and they would be relieved of the work of manual allocation.

As an additional benefit for the ecosystem, the optimized allocation distribution in the subgraphs improves. The ecosystem would benefit because an optimal distribution would not give a few subgraphs the most allocations (the best known or largest projects), but the indexing rewards formula can also make it worthwhile to allocate to smaller subgraphs, which is time-consuming to calculate manually.

Technical Stack

The tech stack for the Allocation Optimization tool contains different libraries as well as tools. Let’s start with the Allocation Optimization Script itself. This core module of the application contains the relevant steps to optimize the allocations so that the highest indexing rewards can be achieved according to the given parameters.

The script is based on the Pyomo optimization modeling language, which is based on Python and is open source. With the help of Pyomo, it is possible to use different open-source and commercial optimizers for the optimization process. We use the open-source GLPK package (GNU Linear Programming Kit). GLPK allows solving large-scale linear programming, mixed-integer programming, and other problems.

The script utilizes GraphQL queries to the meta subgraph to retrieve the relevant information for the allocation optimization (current allocations, network information, etc.). Furthermore, open APIs are used to retrieve price data for the GRT token, ETH, and fiat currencies, as well as to get the current gas price. An ssh tunnel to the Indexer’s graph-node and the database server is used to gather information about the subgraph sync statuses and the latest valid POI for broken subgraphs. RPC calls to Ethereum nodes are used to call the rewards manager contract to get the pending rewards per subgraph.

The data preprocessing, manipulation and preparation are performed using pandas. The allocation optimization script can be executed either in the command line or as a web application.

The web application is based on streamlit. Streamlit is a python package that allows the development of data-driven applications. Visual charts are also displayed in this web interface using plotly.

Use-Cases and Demo

Web App

Check out the Demo!

The web application enables visual optimization of allocations. In the web application based on Streamlit, various metrics and data are visualized:

  • Data from previous optimizations as JSON
  • Price Data (ETH-USD, GRT-USD, Gas Price in Gwei)
  • Historical performance for Closed/Active/Combined allocations
    • Data Table with allocation data by date
    • DIY Chart Builder (WIP)
    • Performance Metrics which visualize rewards per hour and optimized allocations on a timeline
  • Optimization run metrics:
    • Indexer stake, current rewards (hourly/daily/weekly/yearly)
    • Pending rewards, active allocations, average stake/signal ratio, average hourly rewards
    • Current allocation table
    • Distribution of rewards/stake signal ratio
  • Threshold pop up, pieces of information about the subgraphs to allocate to, and allocation commands

The web app makes it possible to follow the optimization process in a simple way. The results are visualized and recommendations for action are suggested. If the results are satisfactory, the commands can be copied for reallocation and executed in the Indexer CLI.

The web app represents a semi-automated approach, where allocations are not yet set or closed automatically. The Web App also serves to build trust in the tool so that users know how the optimization works before they use the fully automated version.

CLI Tool

Check out the Demo!

The CLI tool can be used to automate the optimization and allocation process. In the future, the CLI tool will be executed with the help of a cron job in defined intervals. When the threshold is reached, the allocations will be automatically adjusted according to the optimization.

The CLI tool is also used to run the optimization script without having to call a web interface. No streamlit web server is required to run the script.

The CLI version supports the same parameterizations as the web interface.

What is yet to come

  • Dockerizing the application
  • Automatic optimization and reallocation process in predefined intervals via the indexer agent endpoint
  • Slack Integration
  • Integrating Beta Phase Feedback

Feedback

To improve the tool, we look forward to your feedback. We would like to know which additional parameters would be relevant for you to tailor the optimization process more to the individual indexer. Furthermore, we would be interested to know which additional metrics you would like to see to track the performance of the indexer. Feel free to share your feedback, ideas, and bugs in this forum post.

We would also like to thank The Graph Foundation for awarding us the grant to pursue this project to this extent.

Contact

Check out anyblockanalytics.com. We started participating in The Graph ecosystem in the incentivized testnet as both Indexers and Curators and are Mainnet Indexers from the start. Besides professionally running blockchain infrastructure for RPC and data, we can provide benefits through our data analytics and visualization expertise as well as ecosystem tool building.

Discord: yarkin#5659

E-Mail: yarkin@anyblockanalytics.com

Interested or questions?

 

Freddy Zwanzger
(Co-Founder & Chief Data Officer)
freddy@anyblockanalytics.com
+49 6131 3272372

    

Looking to create an Anyblock account? Takes seconds and it's free!

>> You can also browse related posts below or go back to all posts.

Pin It on Pinterest