Published in


DeFiLlama Integration: Timeswap

In this article, we’ll discuss how we implemented the DeFiLlama integration, created a PR and got our Timeswap DeFiLlama page live (Link).

We discuss going through the process, writing an SDK adapter and our insights on what we discovered while implementing the adapter.

So, dive right in, nerds!

What you’ll learn in the article:

  • What is DeFiLlama
  • Adding a project to DeFiLlama is as simple as opening a PR and filling their already given template
  • Data aggregation can be done through their SDK
  • SDK can filter through events and can call a batch balanceOf on multiple contracts

What is Defi Llama?

DefiLlama is one of the most powerful analytics tool which aggregates key metrics from various Defi products.

The most ingenious part of this tool is that all the data is open source, and getting listed is as simple as opening a PR along with a piece of code, that is, writing an adapter.

“DefiLlama is the largest TVL aggregator for DeFi (Decentralized Finance). Our data is fully open-source and maintained by a team of passionate individuals and contributors from hundreds of protocols.”

DeFiLlama Homepage

How does data aggregation takes place:

We’ll walk over how DefiLlama aggregates the data from protocols and how to get Listed on Defi Llama →

Protocol data is aggregated by DefiLlama via adapters built by their respective community. This is the engine which delivers transparent and unbiased data to the DefiLlama dashboard.

In order to get listed on DefiLlama one has to build an adapter.

Functionality of an adapter is to:

  1. Collect data on a protocol by calling some endpoints or making some blockchain calls.
  2. Compute the TVL of a protocol and return it.

The following are the steps we followed and are listed on their guide as well, which also has the process documented on building the respective adapters: (Link to the guide)

Note: Aggregation on EVM chain can be done via SDK adapters

  • Data aggregation can be done through their SDK
  • SDK can filter through events and can call on chain functions like balanceOf on multiple contracts

You can find the guide on writing a basic SDK adapter in the DeFiLlama Docs: (Linked here)

For reference, here’s the example given in the DeFiLlama docs:

Example from DeFiLlama Docs

And here’s the DeFiLlama adapter we created, which leverages subgraph to collect Timeswap protocol data for aggregating TVL:

Timeswap’s Adapter

Core engine in the adapter is an async function containing the code for calculating TVL via on chain calls {hence no scope for data manipulation, as the adapter code is open source}

  • chainTvl() has a simple functionality that is, to return the balances of assets(&collateral) locked in the protocol.

Since Timeswap TVL is held in the pair contract, the function queries the Timeswap subgraph to get the asset-collateral pair addresses → Link to our subgraph blog

Module Exports allow DefiLlama UI to display the data.

  • TVL is nested inside chain key ‘polygon’.

For reference, here’s our Pull Request to DeFiLlama: Timeswap adapter https://github.com/DefiLlama/DefiLlama-Adapters/pull/2315

After writing the adapter can easily test the adapter via DefiLama test script which outputs the breakdown of the projects TVL in USD.

Hope you learned from this blog and understood the process that we followed for our DeFiLlama integration, we’ll be publishing a lot of insightful technical blogs in the coming days about stuff. Stay tuned and keep following the engineering blog, travelers!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Like Uniswap, but for lending & borrowing