MCDEX Integrates The Graph to Secure Open Data Indexing and Query Support for Trading Activities
MCDEX Integrates The Graph to Secure Open Data Indexing and Query Support for Trading Activities MCDEX Apr 25·5 min read

MCDEX creates a subgraph on The Graph’s hosted service to monitor related new blocks and generate backend data for trading activities. The Graph adds immense value for our development and operation productivity through query support using GraphQL and subgraphs. Subgraphs are open APIs that provide access to on-chain data.

This article elaborates on how the hosted service by The Graph is utilized in our developer’s routine work for MCDEX and why we choose to stick with The Graph throughout our workflow.

For those who are interested in querying data about MCDEX V3 perpetuals, this article also provides a tutorial on how to do so.

Now let’s take a look at how The Graph works as a productivity booster for easy data access.

What is The Graph’s Hosted Service

The Graph is a decentralized protocol for indexing and querying data from blockchains, starting with Ethereum. It makes it possible to query data that is difficult to query directly. With a hosted service that indexes blockchain data. These indexes (“subgraphs”) can then be queried with a standard GraphQL API. In the future, the hosted service will evolve into a fully decentralized protocol with the same capabilities. Both are backed by the open-source implementation of Graph Node.

Why The Graph

Back in MCDEX V2, we used a backend server to monitor the newly generated blocks on the chain, parsing the events to generate the necessary backend data such as transaction data and user position changes.

The work I’ve just described requires the dev team to build our own Ethereum node, keep it synchronized, and handle the rollback of each block.

With the hosted service from The Graph, our development and operation cost has been saved as we no longer need to maintain node operation, block synchronization, rollback, and other related processing works. This product improves the team’s development efficiency as we are able to deploy a subgraph to provide the needed data to be displayed on the front end.

MCDEX V3 Subgraphs

For users looking for data from the Mcdex v3 perpetuals, the subgraph is as below:

Kovan: https://thegraph.com/explorer/subgraph/mcdexio/mcdex3-kovan1

For example, we can get Perpetual’s total volume and LiquidityPool’s pool margin by its symbol or address:

The result:

You can get pool margin and total volume at a pointed block number, then you can get the growth between the pointed block and current block, the query is like this:

The result:

You can get the trade or liquidate data by a query like this:

BlockHandler

The event handler is triggered by events such as token transfer. For data that does not come with an event, we make use of the block handler, which is triggered by each block. Please note that the performance could be heavily affected if every block is processed. One way of optimizing it is to skip some blocks using a timestamp.

About The Graph

The Graph is the indexing and query layer of the decentralized web. Developers build and publish open APIs, called subgraphs, that applications can query using GraphQL. The Graph currently supports indexing data from Ethereum, IPFS, and PoA with more networks coming soon. To date, over 10,000 subgraphs have been deployed by ~18,000 developers for applications, such as Uniswap, Synthetix, Aragon, Gnosis, Balancer, Livepeer, DAOstack, AAVE, Decentraland, and many others.

If you are a developer building an application or Web3 application, you can use subgraphs for indexing and querying data from blockchains. The Graph allows applications to efficiently and performantly present data in a UI and allows other developers to use your subgraph too! You can deploy a subgraph or query existing subgraphs that are in the Graph Explorer. The Graph would love to welcome you to be Indexers, Curators and/or Delegators on The Graph’s mainnet. Join The Graph community by introducing yourself in The Graph Discord for technical discussions, join The Graph’s Telegram chat, or follow The Graph on Twitter! The Graph’s developers and members of the community are always eager to chat with you, and The Graph ecosystem has a growing community of developers who support each other.

The Graph Foundation oversees The Graph Network. The Graph Foundation is overseen by the Technical Council. Edge & Node is one of the many organizations within The Graph ecosystem.

There were more than 2K Curators from over 90 different countries and 172 Indexers from more than 50 countries in The Graph’s testnet. The Graph community is globally distributed, with over 4,500 GRT holders from more than 99 different countries worldwide. Delegation can happen by anyone who holds GRT. Today, there are over 5k Delegators and over 200 Indexers on The Graph Network.

About MCDEX

Mai Protocol V3 designed by MCDEX is an AMM-based decentralized perpetual swap protocol. Perpetual swap is one of the most popular derivatives that has no expiration date, supports margin trading, and has its price soft pegged to index price. We have designed an AMM specially for perpetual trading and it is able to reach 1000x Uniswap’s constant product formula capital efficiency. Furthermore, anyone can create their own perpetual market with the price feed of the underlying asset and choose any ERC20 as collateral. Especially, certain real-world markets are encouraged and will potentially be incentivized on MCDEX V3. Please check out the BigMac Program for specific info. At last, anyone can trade perpetual swaps permissionlessly. Traders’ assets are in the smart contract in a noncustodial way and the process of trading is conducted on-chain completely.

Follow MCDEX on:

Twitter, Discord, Telegram, and Reddit
[]
['Trade', 'Developer Tools', 'Blockchain', 'Cryptocurrency', 'Defi']