Developers Docs
Purpose of SimpleFi's Subgraphs
Before we get to the walkthrough tutorials, it's important to understand the purpose of the subgraphs, so you can develop one that provides accurate DeFi data.
In particular, it will help you decide when to use event handlers or call handler or combination of both to create or update an entity.
The purpose of SimpleFi subgraphs is to track how a user's position in a DeFi market evolves with time. With this information we can easily derive the user's profits and losses.
A DeFi market, is defined as any liquidity pool, yield farm, lending pool or other specific instance of a DeFi protocol. So SimpleFi's subgraphs track, for each user of a market:
  1. 1.
    When and how much the user invests (generally by depositing or staking some amount of one or several assets in the market)
  2. 2.
    How much interest or farming rewards the user accrues over time
  3. 3.
    When and how much the user withdraws/redeems from the market
To collect all this data we create one subgraph per DeFi protocol, which will programmatically capture the following information for each of its markets:
  • General information:
    • Market - generally a contract address or in some cases a unique ID with an address
    • Input Asset - one or several tokens that are deposited into the market by user as an investmentment
    • Positional Asset - this is the tokenized "receipt" that a user often gets when investing in a market. E.g. in a Sushiswap swap pool it is called a Liquidity Provider (LP) token. Or an aToken when lending on Aave. In some cases there is no positional asset
  • When a user invests some Asset in a market
    • Amount - Amount of the Asset that is deposited in the market
    • Positional Asset Amount - Amount of positional asset that is minted by the market due to the investment
    • The date/time of the investment
  • When a user withdraws/redeems some Asset from a market
    • Amount - Amount of the Asset that is withdrawn from the market
    • Positional Asset Amount - amount of the Positional Asset that is deposited to the market in order to withdraw the underlying Asset
    • The date/time of the redemption
  • When a market changes it's internal state that accrues interest on investment
    • Market - Generally a contract address or in some cases a unique ID with an address
    • Input Asset Balances - Generally called reserves of a market
    • date/time
By capturing above data we essentially capture everything we need to know to calculate a user's financial data such as net worth, return on investment, realized returns, non-realized returns (e.g. reward tokens still unclaimed from a yield farm), locked assets and much more. We can also calculate performance of a specific market over a specific period of time by looking at the change in market reserves over that period of time. This is important when calculating things such as impermanent loss.
All this data is then processed in the SimpleFi backend and shown on the ROI dashboard to help users make more informed DeFi investment decisions.
In short, when developing a subgraph, getting accurate data is a priority.
Copy link