At The Graph we’re working to make blockchain data easily accessible, and we love working alongside other teams in the Ethereum community.
Compound Finance is an exciting financial protocol, and today they’re announcing the testnet release of Compound V2! We’ve been working side by side and today we’re happy to share the Compound V2 Subgraph! Now developers, and anyone interested in the Compound protocol, can easily access Compound’s data and pull it straight into their applications using GraphQL.
Since the V1 release in September 2018, Compound has catapulted to having the second highest value of assets locked up of any DeFi protocol, behind only Maker.
Compound is a Money Market protocol built on Ethereum. It allows any person or machine to easily earn interest by lending their cryptocurrency assets. The lent assets can then be used as collateral to borrow other assets locked in the protocol.
The protocol allows for the interest rates to dynamically change with the supply and borrow amounts of each asset. The assets that are currently swappable in the protocol are Dai, Basic Attention Token, Augur Rep, 0x, and Ether.
Compound V2 is an upgrade to the protocol, with many improvements that enable even more assets to be used. Some of the new features include:
- Granular risk modeling — each asset will have its own collateral factor, allowing tokens deemed safer, or riskier, to have appropriately calculated collateral factors.
- Ether can easily be swapped with any token, no need for Wrapped Ether! This greatly improves the user experience.
- The creation of the ERC-20 compliant CToken — which allows lending and interest within the protocol to be tokenized.
The Compound V2 Subgraph
The Compound V2 Subgraph is now available on Graph Explorer! You may be wondering what kind of information you can gather from a subgraph?
A subgraph defines a standard way to index data from blockchains and storage networks. It specifies what data sources to listen to, how to transform that data, and a GraphQL schema for querying. Once built, a subgraph can be compiled and deployed to a Graph Node which syncs the data and generates a GraphQL endpoint with support for filtering, sorting, pagination, websocket subscriptions, and more.
As a developer, you can deploy to a standalone Graph Node, to our Hosted Service, or soon, the decentralized network.
Graph Explorer is a unified destination to discover subgraphs by the leading projects in the Ethereum ecosystem.
Compound V2 Subgraph Specifics
The Compound V2 subgraph provides access to all the data in the protocol. We’ve outlined some key points that developers, or anyone in the Compound Finance community will find interesting.
- Data on each of the 5 markets is updated on every block that a transaction is triggered within the market.
- Future markets added to the protocol will be tracked by dynamically watching for new markets added to the “Comptroller” contract.
- The subgraph deals with all decimal amounts and exchange rates behind the scenes. So instead of having a raw smart contract read of your cDAI balance returned as
12597849345, the query returns
- ETH and USD ratios for each token, making it easy for developers to derive the value of the assets.
- The lending interest an account has earned on each asset within the protocol is recorded and recalculated each time it interacts with the protocol.
- The borrow interest accumulated is also available.
- It tracks all borrow and lending assets of an account. The subgraph can then provide the account liquidity, as well as the amount of ETH it can borrow above the collateral ratio. This is extremely useful for protecting assets from liquidation. It is even more useful for a liquidator in the market, that can query the subgraph for the collateral ratio of all accounts, and identify risky accounts that can be liquidated at a premium.
Compound V2 Mainnet
Compound V2 is only live on testnet, so make sure to follow the development for the official mainnet release! The Subgraph will be kept in sync with the mainnet release, and any minor changes will be accounted for and updated. The most up-to-date subgraph will always be available for querying, and can be interacted with in the playground of Graph Explorer.
Join Us to Build Your Own Subgraph
Each day at The Graph we are pushing to make more blockchain data easily accessible. Our team as well as our community members are continuing to deploy new subgraphs every day, and we’re just getting started!
If you are a developer interested in building a subgraph, we’re excited to help you get started! Please come chat with us in our Discord channel!
And to any protocols interested in working together, whether your contracts are live on mainnet or not, please reach out as well! We’d love to partner and help you operate a fast and reliable GraphQL API for applications.