Tinyman TVL

    How can the TVL of a whole DEX in Algorand be calculated? Using the available on-chain data from Flipside Crypto we can calculate the TVL and really get deep into how much value do users deposit on a platform like Tinyman.

    Tinyman X Defi Llama

    What is Tinyman

    Tinyman is a decentralized exchange (DEX) in Algorand. It launched at the end of 2021 and it runs as a permisionless platform - any user can create a liquidity pool (LP) or swap in one LP between two Algorand Standard Asset (ASA) tokens.

    This outlines the two type of users in the platform:

    • Providers send the same USD value of two different ASA tokens to a existing pool (or creates a new one) and in return they receive a pool token which is a representation of those tokens sent. They will receive a proportional part of the swapping fees according to the percentage of the pool they own. They can redeem their original investment by sending the pool token back to the LP.

    • Swappers send one ASA token to a pool and receive an equivalent value in USD to the ASA token pair in the pool, paying a swap fee as their service cost.

    Total TVL

    The following results table gives some context on the asset_TVL CTE:

    • For 8876 liquidity pools made with 6722 different ASA, it contains dover 370k rows of data since October 2021
    • Max asset TVL 2 Quadrillion! and min asset TVL of -20k - numbers which make no sense!

    Pool balances

    The flipside_prod_db.algorand.transfers table contains information of all ASA token transfers in Algorand.

    Some of the addresses in Algorand have been labelled by Flipside data curators and by querying the flipside_prod_db.algorand.labels table with the condition label = 'tinyman', all Tinyman pool addresses and names will be obtained.

    By joining both tables above I can create a CTE for the deposits of all pools and another one for the withdrawals, which will be the basis of this analysis.

    The next step will be to aggregate the daily inflows and outflows by pool and asset. Each pool will have 3 assets: asset pair 1, asset pair 2 and pool asset. By multiplying the asset amount by the daily price we can solve the pricing of the pool token indirectly since they have no price in the tables as they are not swapped. Therefore, we can calculate the total USD balance for each of the assets in the swap pair per pool over time. A CTE named asset_TVL will give this results and be the basis for the calculation of the Total TVL.

    Results

    Defi Llama's Tinyman TVL dashboard contains the TVL value over time with a toogle to show it in USD and ALGO. It also contains some basic protocol information and the methodology used for the calculation, which in this case it is a JavaScript code calling Tinyman's API which returns the data set. There is one variable called misrepresentedTokens which is set to true. This gives us already a clue on what we might be up to...

    Some pools in Tinyman have unverified ASA tokens, usually having such a low liquidity that they cannot be used as intended. Since the platform is permisionless, anybody can create a meme coin with a high supply and by creating a pool are creating a market for their coin, with its supply and demand dynamics. These high supply, low liquidity coins are very volatile and can account for very big TVL if calculated with the same methods as for high liquidity pools, where the market is more mature and efficient to give a correct valuation.

    I believe that Defi Llama's calculation method derived from Tinyman's API already filters most of these problematics tokens out, but there is some improvement to be made as seen in the following graphs (extracted from Defi Llama on June 24th)

    What is Defi Llama?

    DefiLlama is an open-source DeFi analytics dashboard which commits to provide Total Value Locked (TVL) data in a transparent and accurate way. Currently providing this metrics for 1650 protocols in 124 blockchains, it is one of the leading TVL aggregators overall.

    Methodology

    The term TVL can be defined by the total value of all assets locked in a project or smart contract. Although it is quite an easy concept, practical calculations of it can get very tricky.

    • First part of the calculation would be to get the balances on all assets participating in a project, like liquidity pools in a decentralized exchange (DEX) or staked amount in a protocol. In chain like Ethereum, smart contracts can have assets in them, in other like Algorand withdrawals and deposits would need to be aggregated to get the total balance over time.

    • Secondly, the price of each asset needs to be accurately gathered in order to make a sound calculation. Different metods could be getting the price directly from indexes like CoinGecko or CoinMarketCap or calculating it from on-chain data.

    • Lastly, the total TVL of all pools shal take into account the non-liquid pool and the mentioned high supply, low liquidity tokens.

    db_img
    db_img

    Key points for these visualizations:

    • Two sharp spikes can be seen in November 12th 2021 and June 1st 2022 in both denominations. This don't represent real TVL.

    • The gap in TVL in January 2022 was caused by an exploit on the protocol. Users were prompted to retrieve all funds from the platform (which most did already when the first news came out) and Tinyman launched a new 1.1 version where all pools were created again once the bug was solved. For the users which lost funds, Tinyman has a compensation program in place through staking rewards. As seen above, locked amount of ALGO recovered by February although in USD it has still not reached levels before the exploit.

    • The spike in April 14th was caused by the launch of the Algorand Governance Period 3, where gALGO3 tokens where given to users who locked their ALGO in the Governance contract as a liquid staking programm - throughout Algorand's ecosystem this triggered a wave of staking, lending and borrowing activities that drove growth of several platforms, including Tinyman.

    • Terra's collapse in May 11th 2022 drove the market into a depression, which also affected Tinyman. By comparing both charts, it can be seen that the value in ALGO dropped slightly, meaning that users didn't withdraw funds from the platform and it was just the ALGO price that sinked (as practically all crypto market did)

    Price

    For this analysis, the flipside_prod_db.algorand.prices_swap table is used to price the ASA tokens using on-chain swaps. Price is calculated by using all swaps within two standard deviations from the hour average price, calculating the average price at the dex level, then weighting the dex price by the previous day's volume to create a weighted average across all dexes.

    A daily average price for each token has been derived from the mentioned table in an attempt to filter out high volatility spikes.

    Loading...
    Loading...

    The approach followed to calculate Total TVL value will be to divide pools in terms of their volumes:

    • Main pools will be defined as pools having at least once a daily TVL bigger than 3M USD. The pool addresses will be manually selected to filter the most known asset pairs - ALGO-USDC, USDC-USDT, goBTC-ALGO, goETH-ALGO, YLDY-ALGO, gALGO3-ALGO, etc. These pools have a relatively stable total TVL and will be accepted to the calculation without filtering.

    • Secondary pools will be all the other pools not in the above group, having less liquidity and prone to higher volatility specially in pools where ALGO pairs itself with a very low liquidity, high supply coin (there are multiple examples of meme coin in Algorand). This pools will be splitted into 4 subgroups and, instead of adding both assets TVL to obtain the pool TVL, one of the assets TVL will be multiplied by 2 to define the pool TVL:

      • Pools ASA - ALGO: the pool TVL will be calculated as 2 * ALGO TVL since ALGO will have lower volatility than the asset pair.

      • Pools ASA - USDC: the pool TVL will be calculated as 2 * USDC TVL since USDC will have lower volatility than the asset pair.

      • Pools ASA - USDT: the pool TVL will be calculated as 2 * USDT TVL since ALGO will have lower volatility than the asset pair.

      • Pools ASA - ASA: the pool TVL will be calculated as 2 * the ASA TVL with lower asset_id with the assumption that higher asset_id tend to be from newer coins where the probability of it having higher volatility as older, more stablished ASA is high.

    • Secondary outlier pools will be defined as secondary pools which have a daily TVL bigger than 3M USD. These values tend to bring the higher inaccuracy to the TVL and therefore will be omitted for the calculation, assuming an error around 5% on certain days.

    Loading...
    Loading...

    Figure 2. shows the outliers as secondary pools with a daily TVL bigger then 3M. These have not been taken into account in the total TVL calculation. There are 67 such outliers with ASA such as TESTING DONT BUY 3, CoffeeCoin, Infinity of Anarchy, Cumsock and other which is quite difficult to argue that such projects are able to lock this value on a LP.

    Figure 3. show the TVL from the secondary pools after filtering with the method explained in the Methodology section. The improvement compared to Figure 1. is very clear.

    Figure 1. shows the TVL of secondary LP as the sum of both asset's TVL. This leads to inaccurate results due to the impact of low liquidity, high supply and volatility assets.

    Loading...
    Loading...

    Figures 4. and 5. show the total TVL by type of pool as defined in the Methodology section, in absolute value and normalized.

    Figure 6. shows the total TVL, the comparison with Defi Llama's dashboard shows that both results are relatively close to each other, with days where the calculation yields very similar values with both methods (December 1st 2021 29.19M compared to 29.28M - less than 0.5% error).

    The advantage of the method used here is that we can tweak the filtering values and we could analyse spikes like the one happening in June 1st in Defi Llama. On this day, according to Defi Llama, 44.75M USD were locked. I trust the calculated value of 19M much more since it is highly unlikely that in middle of a bear markets Tinyman could lock a record total value in 24h just to lose 50% the following day.

    Loading...