Querying Liquidity on Curve and Terra’s downfall with the Graph and Subgrounds (Python)

In April I listened to a Laura Shin episode with Kevin Zhou on USDN de-pegging and that got me thinking what would a UST depegging look like and how it could start a contagion causing the system to collapse. A couple days later I received a data analyst assignment that asked to create data visualizations in Python and a Dune dashboard on any of these protocols: Avalanche, Terra, Solana, Ethereum, Thorchain, Cosmos, Polkadot, Near, Compound, Curve, MakerDAO, Lido, Frax, Anchor, Aave, dYdX, Convex, Osmosis, Uniswap, Yearn, or Tokemak.

Several protocols in that list were parties in the so-called “stablecoin wars” that was related to my depegging interest and so I decided to explore what ensures the stability of stablecoins and what does it take to win (or lose) those wars, also known as “liquidity” or “the Curve wars”. It seemed an important macro subject because liquidity is the bandwidth markets need to operate. In DeFi, it comes from the liquidity pools (the trading pairs on Automated Market Makers). Liquidity in stablecoins in particular, is crucial to moving forward in the markets. On a more individual practical level, I wanted to know how to make better decisions as a liquidity provider in those pools.

Then the collapse happened, and with actual data at hand, I revisited the project to look at the on-chain dynamics of the event. As a result, the dashboard is divided into 2 parts: first, it looks at how Curve created an ecosystem of incentives around it so attractive that protocols fight over it and second, what did liquidity look like in the Curve’s UST-related pools that contributed to the downfall of the stablecoins wars’ fiercest competitor Terra.

Tools

For the assignment, I was familiar with the Dune part, but needed to find a python tool for the other part. Luckily I heard about a community of on-chain analysts MetricsDAO, so I looked at the tools they use and found this workshop series that showcases Subgrounds, a python wrapper for querying the Graph’s pre-modeled data into your notebook. It also uses dash to build low-code data-drive web apps. It’s built by Playgrounds, a new organization dedicated to advancing on-chain analytics through open-source tooling and infrastructure, recreating web2 analytics stack on web3, and empowering people to do their own analytics - which resonated with me.

In addition, I was excited to use the Graph as it became a core infrastructure project necessary for building decentralized applications. A decentralized query protocol for blockchains, it was created as an alternative to API provider companies. It decentralizes the query and the API layer of web3 and uses a query language created by Facebook called GraphQL (source).

It took me some time to understand the logic of the subgraph, i.e. how the endpoints, or fields, and their relations are organized in a database. Some, like the emissions subgraph, really got me going in circles. Also, the filtering syntax had to be figured out more or less blindly, by trial and error.

But it was worth it. First, being able to use Python gives the Graph and Subgrounds the flexibility unmatched by SQL and Dune. Second, in terms of speed, indexing network / node type data is faster than querying a relational database. Complex queries typically run faster in graph databases than they do in relational databases, which require complex joins on data tables to perform queries (source).

Conclusion:

Having been immersed in the subject of the dashboard, I saw first hand how a lot of the crypto protocols are trying to get the flywheel going, sometimes generating value from nothing. It will be interesting to see what mechanisms of incentives will prevail. The curve system is a complicated web of interlocked incentives but looking into its data can help verify where the risks, as well as, the money-making opportunities are. The project taught me 1/ to look at the macro indicators of a crypto system, specifically, liquidity, as it can be limited in crypto - and to keep an eye on the available exits; 2/ not to assume that a stablecoin is stable, but to figure out what it is backed, or collateralized, with; 3/ to always probe into where the yield is coming from.

So far DeFi has mostly survived this bear cycle punctuated by the Terra collapse, even though CeFi suffered, but we’re learning that trust in these trustless protocols is perhaps the most important metric a protocol can aspire to capture and accumulate.

https://concaves.herokuapp.com/

comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium vimeo