👩‍💻
Builder Portal
  • Sovryn Builder Portal
    • Contribution
  • Design System
    • Design principles
    • Structure
    • Usage by Sovryn
  • UI Library
    • Overview
    • Getting Started
    • Atoms
      • Accordion
      • Badge
      • HealthBar
      • Button
      • DynamicValue
      • Heading
      • ErrorBadge
      • Icon
      • Input
      • Lottie
      • Paragraph
      • Toggle
      • Link
      • Checkbox
    • Molecules
      • AmountInput
      • ContextLink
      • Dialog
      • Dropdown
      • ErrorList
      • Footer
      • FormGroup
      • Header
      • HelperButton
      • Menu
      • NavMenuItem
      • Notification
      • Overlay
      • Pagination
      • RadioButton
      • RadioButtonGroup
      • Select
      • SimpleTable
      • StatusItem
      • Table
      • TableBase
      • Tabs
      • Tooltip
      • TransactionId
      • VerticalTabs
      • VerticalTabsMobile
      • WalletContainer
      • WalletIdentity
    • Working with Components
    • Links
    • Contribution
  • Sovryn SDK
    • Smart Router
      • Creating a New Swap Route
      • Available routes
        • AMM
        • MoC integration
        • MYNT bAsset
        • MYNT fixed rate
    • Sovryn Onboard
      • Installation
      • Usage
      • Custom Connectors
      • Custom UI
      • Contribution
    • The Graph
      • Overview
      • Usage
      • Sovryn Subgraphs
      • Advanced Usage
  • sovryn.app
    • Overview
    • Sovryn UI Library Usage
    • The Graph Usage
    • Links
    • Contribution
    • Dapp specific components
      • MaxButton
  • Smart Contracts
    • Overview
    • AMM
      • Liquidity
        • V1 Converters
        • V2 Converters
      • Conversion
      • Wrapper
        • V1 liquidity
        • V2 liquidity
        • Swaps
    • Sovryn Protocol
      • Lending
        • Mint
        • Burn
      • Borrowing
        • Borrow
        • Repay
      • Margin Trading
        • Open
        • Close
      • Collateral Management
    • Liquidity Mining
      • Deposit
      • Withdraw
      • Rewards
    • FastBTC
      • RSK->BTC
    • Bitocracy
      • Staking
      • Governor
      • Fee Sharing
      • Vesting
    • Zero
      • Borrower operations
      • Trove Manager
      • Satability Pool
      • Rewards
    • Mynt & DLLR
      • Basset to Masset Conversion
      • Masset to Basset Conversion
      • MOC Integration Conversion
Powered by GitBook
On this page
  • How we are using The Graph at Sovryn
  • Benefits for Sovryn
  • Microservices
  • Using The Graph
  • Some useful links and documentation:
  1. Sovryn SDK
  2. The Graph

Overview

PreviousThe GraphNextUsage

Last updated 1 year ago

How we are using The Graph at Sovryn

The Graph solves the problems outlined above with a decentralized protocol that indexes and enables the performant and efficient querying of blockchain data. These APIs (indexed "subgraphs") can then be queried with a standard GraphQL API. Today, there is a hosted/self-hosted service as well as a decentralized protocol with the same capabilities. All of these are backed by the open-source implementation of . This means that no matter which method is used, the queries used to access the data will never need to change.

When we first launched the Sovryn dapp, we built our own indexing server that listens to, processes and stores transactions, and then an API on top of this. However, this quickly became resource and time-consuming to maintain and scale to the levels we require - for this reason we have migrated any of this logic from the original service to our new Sovryn subgraph.

As mentioned above, the Graph Protocol offers two different methods for capturing and exposing data:

  1. Self-Hosted/Hosted Subgraph

  2. Decentralized Network Subgraph (hosted on the network itself)

Currently The Graph does not support Decentralized Network Subgraphs for the Rootstock network so we are using our own hosted subgraph - in the future when support for this is added, the transition can easily be made by pointing our dapp frontend to the Decentralized Network Subgraph, without needing to rewrite queries for additional optimizations. In addition, as the queries are written in the same GraphQL syntax regardless of what blockchain is used, this flexibility ensures a smooth migration with minimal changes if Sovryn were ever to branch out to other EVM compatible chains.

Below we have a high level view of how the information flows through the Graph Network to the Sovryn dapp:

The flow follows these steps:

  1. Sovryn adds data to the Rootstock blockchain through a transaction on a smart contract.

  2. The smart contract emits one or more events while processing the transaction.

  3. Graph Node continually scans Rootstock for new blocks and the data they may contain for our subgraph.

  4. Graph Node finds Rootstock events for your subgraph in these blocks and runs the mapping handlers you provided. The mapping is a WASM module that creates or updates the data entities that Graph Node stores in response to Rootstock events.

  5. The decentralized application queries the Graph Node for data indexed from the blockchain, using the node's GraphQL endpoint. The Graph Node in turn translates the GraphQL queries into queries for its underlying data store in order to fetch this data, making use of the store's indexing capabilities. The decentralized application displays this data in a rich UI for end-users, which they use to issue new transactions on Rootstock. The cycle repeats.

Benefits for Sovryn

  • Anyone can query subgraphs. Out-of-the-box support for the flexible GraphQL API, which makes it easier for external developers to interact with data from the Sovryn ecosystem, with no reliance on Sovryn to provide data in a specific format

  • Robust and reliable data

  • Less developer effort required to maintain indexing server

  • Faster iteration for data queries and debugging logic

  • Better developer experience

  • Greater transparency of how values are derived from on-chain data

  • Easy transition to other chains if required

Microservices

While The Graph is the ideal framework for indexing blockchain data, it does have certain limitations.

One of these is that it can only react to blockchain data, but it cannot run scheduled jobs. Why is this an issue? Say, for example, you want to know what the 24-hour price change is of a token, and you want this data to be updated every 30 seconds. The Graph cannot do this kind of processing at scale. As an aside, The Graph can respond to individual blocks instead of events, but this leads to much slower syncing times.

Our solution has been to build a suite of microservices that use data from The Graph (and sometimes directly from the contracts) to handle these types of cases. Our suite of microservices and API endpoints use The Graph as their source of truth, add some additional logic/processing, and serve this data as an API in the format that the Sovryn dapp (or other products/parties) require.

Our microservices are easily maintainable and extensible, and have paid off a large amount of the technical debt in our backend data services.

Using The Graph

Users are encouraged to explore and use The Graph. Community members on various projects have built entire dashboards around queries to The Graph and similar blockchain databases.

The following repositories contain code and documentation regarding Sovryn subgraphs:

Some useful links and documentation:

To help users get started, we have provided documentation. We encourage you to ask questions on Discord and make suggestions on how to improve the documentation. Please share your insights with the community if you develop an interesting query.

Sovryn Subgraph:

Zero Subgraph:

AMM APY:

Graph Wrapper:

Graph Protocol documentation:

GraphQL documentation:

The Graph Technical Usage
https://github.com/DistributedCollective/Sovryn-subgraph
https://github.com/DistributedCollective/Zero-subgraph
https://github.com/DistributedCollective/sovryn-amm-apy
https://github.com/DistributedCollective/Sovryn-graph-wrapper
https://thegraph.com/docs/en/
https://graphql.org/learn/queries/
Graph Node