Compound is an open-source protocol for algorithmic, efficient Money Markets on the Ethereum blockchain. This Subgraph ingests the V2 contracts of the protocol. See here for the V1 subgraph.
This subgraph can be found on The Graph Hosted Service at https://thegraph.com/explorer/subgraph/compound-finance/compound.
You can also run this subgraph locally, if you wish. Instructions for that can be found in The Graph Documentation.
The subgraph will be kept in sync with the development of Compound-V2 until the official mainnet launch. The Hosted service will always be updated with the most recent subgraph.
After that, the only changes to V2 should be new assets added, which the subgraph will stay up to date with. This may be possible to do so dynamically, without subgraph updates. To be concluded.
These contracts were left out:
PriceOracle.sol
- For the testnet this is just a simple price oracle, it will be updated to a real one on mainnet, and likely included in the subgraphStableCoinInterestRateModel.sol
- No data was chosen to be sourced from hereStandardInterestRateModel.sol
- No data was chosen to be sourced from here
The ABI used is ctoken.json
. It is a stripped down version of the full abi provided by compound, that satisfies the calls we need to make for both cETH and cERC20 contracts. This way we can use 1 ABI file, and one mapping for cETH and cERC20.
Below are a few ways to show how to query the Compound V2 Subgraph for data. The queries show most of the information that is queryable, but there are many other filtering options that can be used, just check out the querying api.
{
markets{
id
symbol
accrualBlockNumber
totalSupply
exchangeRate
totalReserves
totalCash
totalDeposits
totalBorrows
perBlockBorrowInterest
perBlockSupplyInterest
borrowIndex
tokenPerEthRatio
tokenPerUSDRatio
}
}
Commented out values are temporarily not being used.
{
users{
id
countLiquidated
countLiquidator
# accountLiquidity
# availableToBorrowEth
# totalSupplyInEth
# totalBorrowInEth
cTokens{
id
user
accrualBlockNumber
transactionTimes
transactionHashes
cTokenBalance
underlyingSupplied
underlyingRedeemed
# underlyingBalance
# interestEarned
totalBorrowed
totalRepaid
# borrowBalance
# borrowInterest
}
}
}