DefiLlama / dimension-adapters

91 stars 1.01k forks source link

[Q] Replacing Anyswap's Stablecoins #664

Closed ftm1337 closed 1 year ago

ftm1337 commented 1 year ago

Recently, Multichain's (Anyswap) bridge collapsed and their tokens depegged to 1/15th of their previously perceived values.

Defillama uses a hard mapping on multiple chains that map mc's tokens like USDC or USDT to the real USDC or USDT on the Mainnet Ethereum. This results in a bugged calculation that inflates TVL, Volume, Fees, etc on these networks by upto 20x more in adapters that use offchain indexing like those that use their own subgraphs or custom APIs to feed data into DefiLlama.

A notable example is Fantom, where DAI is trading at 0.08, fUSDT at 0.13, USDC at 0.18 and so on.. The DEXes that use subgraphs are currently showing 5-15x more $ values in their TVL, Volume, Fees adapters.

Possible solution would be to identify other sources of stablecoin pricing and use that to calculate valuations. For example, on fantom, there are multiple native stablecoins like MIM & FRAX and multiple bridged tokens like axlUSDC that have been on the network since years and are still functioning properly, trading at $1.

I'm not sure about what and where we need to make the required changes in the DefiLlama repositories, so opening this thread in both repos (tvls & dimension). One solution for Volume & Fees would be to use on-chain / event-based adapters like we have for solidly forks, but would be quite a bit laborious for 100s of projects..

edit: On fantom, I noticed axlUSDC was showing up a price of $0, evident in adapters such as e3, equity, equalizer, spookyswap etc protocols that have majority usage of axlUSDC as primary stablecoin. (https://www.coingecko.com/en/coins/axelar-usdc)

0xngmi commented 1 year ago

we set the price of all multichain assets to 0, although in some dexs these assets are priced by using the internal price against ftm

if you found a concrete case of mispricing related to this, could you point us to it?

ftm1337 commented 1 year ago

@0xngmi here's what defillama volume (/dexs) board shows for fantom: image

(starting with the first one as example) the adapter for spooky uses https://api.thegraph.com/subgraphs/name/eerieeight/spookyswap , running a simple query on it gives image which is what defillama shows. (the $5.28m volume for yesterday). if we compare it to other trackers, like gecko terminal Screenshot_2023-07-29 Top SpookySwap Pools by 24h Transaction GeckoTerminal or dexscreener image or dextools image

then we get the number at around $1.1m, and if we check the price of FTM, spooky's subgraph returns $1.29 = 1 FTM (i wish!) image the difference in prices is roughly the same 5x that USDC (multichain) has depegged to ($0.19 right now).

all of the other dexes that use subgraphs have similar issues.. with numbers being inflated about 5x. I'm not sure about wagmi's numbers though.. their site reports $30 while dexscreener says $25 (https://dexscreener.com/fantom/f:0xaf20f5f19698f1D19351028cd7103B63D30DE7d7).. meanwhile, on defillama we see $3m+ .. i'm guessing its because of something related to its CL math not sitting well with depegged token's prices in the subgraph.. idk tbh.

i tried writing adapters that would iterate over the "Swap" events (similar to equalizer's adapter), but get with an out-of-memory heap error on my local machine when i do the yarn test dexs spooky2.. i guess its probably because of the millions of swaps that spooky has had coupled with the smol ram i have available. so maybe someone else can give it a shot..

ftm1337 commented 1 year ago

It has got worse now.. over-reporting numbers by 10x with anyswap's USDC depegged to $0.1 :sweat_smile: image for example, spooky should have 600K volume, instead of 6M image

0xngmi commented 1 year ago

sorry for lack of reply here, didnt see your messages

I've just pushed an update to most fantom dexs to price volume against FTM instead (and then we price FTM against coingecko). Haven't managed to match dexscreener volumes but dont see where the issue could be in our new methodology

As for wagmi, we'll completely delist it from fantom

0xngmi commented 1 year ago

This was all fixed a week ago, so closing due to inactivity

ftm1337 commented 1 year ago

thanks 0xngmi! the numbers look quite accurate now, similar to those reported at other sites. and the modified adapter is going to be quite useful if some other chain has a similar issue there are still a few old ones with the wrong numbers on fantom.. i'll try to rewrite all those this week, and add the few missing ones (spirit v1, velocimeter)..