Updated 142 days ago

DeFi SCROLLer

“The first protocol-tailored PnL tracker” This product solves the problem of DeFi investors struggling to manage and track their positions and profits easily. Many current DeFi protocols only provide the current value of a position, but do not offer Profit and Loss (PnL) tracking services. This product tracks the PnL of different DeFi protocols and provides clear and accurate insights into a user's earnings, enabling better understanding and decision-making in DeFi investments.

Frontend Repo

https://github.com/swimmiee/defi-scroller

Subgraph Repo

https://github.com/swimmiee/defi-scroller-subgraph

Screenshot 2024-04-27 at 9.04.02 PM.png

Problem

We found that many DeFi investors struggle with managing their positions and tracking how much they have earned. Actually, most DeFi protocols currently only provide the value of the current position, but do not support PnL(Profit & Loss) tracking services, as the value of the position is constantly changing and so are the prices of the tokens that make up the position.

So we created a tracker to easily monitor the PnL of different DeFi protocols on Scroll. Here are our 3 key features.

General Subgraph Template

We've created a subgraph template that allows for protocol-specific PnL tracking. Here are the main elements that make up this template

Snapshots

In most DeFi Yield protocols, apr is highly imprecise and time-varying. Sometimes the yield is overestimated by volatility in token price or quantity, resulting in unreliable APR values.

To accurately analyze the performance of a position, we need to properly analyze the quantity and price changes of the tokens that make up the position over time. To solve this problem, we take a daily snapshot of the amount of tokens each position holds and track the daily value changes of the positions.

We utilize Subgraph's blockHandler to periodically index the value of each position. The maximum length of time the handler function can run once is 1200 seconds, so instead of checking all positions in one block, we split the 24 hours into multiple batches to run the blockHandler so that we can take a snapshot of all positions at least once daily.

Calculating the current value of each position is protocol-tailored. For example, in SyncSwap, it is calculated from the balance of LP tokens, the reserve amount of token0 and token1, and totalSupply. By indexing these values whenever position change events such as mint, burn, swap, and sync occur, it is possible to snapshot all positions with zero eth_calls instead of having to make eth_calls every time a snapshot is taken.

Changes

Each subgraph triggers eventHandler whenever a new position is created, changed, or removed.

The types of position changes can be categorized into the following actions:

  • Deposit
  • Withdraw
  • Harvest
  • Transfer (Send / Receive)

Position changes are tracked by indexing the position change events that occur in each protocol by corresponding to these actions.

For example, when Uniswap V3's “IncreaseLiquidity” event or SyncSwap's “Mint” event are emitted, they are indexed as the Deposit action. When “Collect” event is emitted to collect fees in Uniswap V3, it can be indexed as the Harvest action. When SyncSwap's LP tokens or Uniswap V3 position NFTs are transferred to another wallet, a Send action is recorded for the position owned by the sending wallet and a Receive action is recorded for the position owned by the receiving wallet.

We used this template to create PnL trackers for Ambient, SyncSwap, and Uniswap V3, each of which are representative yield protocols deployed on Scroll.

The graphql endpoints for each subgraph are as follows:

Uniswap V3 https://api.studio.thegraph.com/query/73090/test-uniswap-v3-scroll/v0.1.1

SyncSwap https://api.studio.thegraph.com/query/73090/test-syncswap-scroll/v0.1.1

Ambient https://api.studio.thegraph.com/query/73090/test-ambient-scroll/v0.1.0

For more information and the schema of the template, see the code at the link below: https://github.com/swimmiee/scroll-defi-subgraph/blob/main/schema.graphql

PnL Tracker

The current value, snapshot, and change history of all positions allows users to see how much they have earned from their DeFi investments. It's very easy to see how much you've earned in traditional finance. This is something basic that all traditional financial services provide, but DeFi protocols don't currently offer this feature, or are inaccurate.

We would like to utilize this subgraph template, which can be applied to all DeFi protocols in general, to quickly create subgraphs to track DeFi PnL for each of the various protocols. Screenshot 2024-04-27 at 8.43.32 PM.png

DeFi Insights

Since we index all positions across different protocols, we can provide insightful information about each DeFi investments, such as:

  • Average APR for Liquidity / Deposit Pools
    • We can provide more accurate performance based on historical data of all positions in the pool.
  • Best Performance project
    • Most DeFi protocols typically focus on the change in the token amounts when measuring investment performance. But due to the volatile price of the tokens that make up a position, we also need to focus on the change in the dollar value of your position.
    • For example, an investment product might offer a high APR that significantly increases the quantity of tokens. But if the token price drops sharply, the overall position value may decrease. On the other hand, a product may not increase the quantity of tokens much, but if the token price rises significantly, the APR may seem low while the position value may increase substantially.
  • Trending Positions
    • You can analyze which investment pools have the most position deposits over a certain period of time, or which have the most inflows, to analyze which investment products have been the most popular lately.
  • Whale Positions
    • You can track in real-time where whales have invested, or how their positions are performing, as shown below.

Screenshot 2024-04-27 at 8.43.42 PM.png

By providing a more detailed analysis of DeFi position PnL, which is not available in current DeFi protocols, users can get the information they need to invest in DeFi. This will greatly contribute to resolving the information asymmetry in DeFi, and will greatly contribute to the popularization of DeFi investments.