This guide will assist you in creating a dashboard on the Top Ledger platform, which displays a variety of key metrics for the LST ecosystem on Solana.
Let’s calculate some important metrics for the LST ecosystem and add them in a dashboard.
Deposits & Withdraws
We will start by calculating deposits and withdrawals for various platforms in the LST ecosystem. The chart below shows the weekly volumes.
Now, let's go through the SQL code for the above chart. The query runs on the liquid_staking table available in the Top Ledger platform.
The SQL code start first with staking multiple types of LS txns and volume associated with them on a daily level. Then it union them in a nested expression to gather all the txns and volume associated with staking and un-staking events in the ecosystem. Finally, the code groups by the data for various platforms and then cluster the it over weekly interval.
withcte_rewardas (selectdate(block_time) as block_date,stake_pool,signer,tx_id,(staking_reward/1e9 )as amountfrom tl_solana.liquid_stakingwhere instruction_type in ('UpdateDeactivated','UpdateActive') ),cte_depositas (selectdate(block_time) as block_date,stake_pool,signer,tx_id, case when instruction_type in ('Deposit','DepositSol','DepositStake') then amount/1e9 else -amount/1e9 end as amount
from tl_solana.liquid_staking where instruction_type in ('Claim','LiquidUnstake','Deposit','WithdrawStake','WithdrawSol','DepositSol','DepositStake')
),cte_deposit_stakeas (select a.block_date,stake_pool,signer,tx_id,amount*sol as amountfrom (selectdate(block_time) as block_date,signer,stake_pool,tx_id,mint_amount/1e9 as amountfrom tl_solana.liquid_stakingwhere instruction_type in ('DepositStakeAccount') )ajoin (select a.block_date,b.price_in_usd /a.price_in_usd as solfrom (select*from tl_solana.priceswhere mint='mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So' )ajoin (select*from tl_solana.priceswhere mint='So11111111111111111111111111111111111111112' )b on a.block_date=b.block_date )bon a.block_date=b.block_date ) selectmonth, stake_pool,amountfrom( select date_trunc('week',block_date) as month, case when stake_pool='8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC' then 'msol'
when stake_pool='stk9ApL5HeVAwPLr3TLhDXdZS8ptVu7zp6ov8HFDuMi'then'bsol'when stake_pool='Jito4APyf642JPZPx3hGc6WWJ8zPKtRbRs4P815Awbb'then'jitosol'when stake_pool='CtMyWsrUtAwXWiGr9WjHT5fC3p3fgV8cyGpLTo2LJzG1'then'jpool'--when stake_pool='7ge2xKsZXmqPxa3YmXxXmzCp9Hc2ezrTxh6PECaxCwrL' then 'daosol'when stake_pool='CgntPoLka5pD5fesJYhGmUCF8KU1QS1ZmZiuAuMZr2az'then'cgntso'when stake_pool='2qyEeSAWKfU18AFthrF7JA8z8ZCi1yt76Tqs917vwQTV'then'laineSOL'when stake_pool='DqhH94PjkZsjAqEze2BEkWhFQJ6EyU6MdtMphMgnXqeK'then'mrgnLST'elsenullendas stake_pool,sum(amount) as amountfrom (select*from cte_depositunion allselect*from cte_rewardunion allselect*from cte_deposit_stake )group by1,2 )where stake_pool is not nullorder by1desc
And the widget displays the deposits as positive while withdraws as negative, providing a fine sense of how much of net amount is getting staked every day.
TVL
Total Value Locked or TVL is the amount which is stacked or locked as LST in a pool at any moment. So TVL represents the most crucial metric for LST platforms. It tells us about the health and hence the confidence people has in some LST platform. So let's visualize the TVL of various platforms with the help of some charts
Since TVL is nothing but accumulation of net deposits over time, the query below, like the previous one, starts with computing deposits and withdraws and the subtract the withdraws from deposits to get daily net deposits. And then in the next step accumulate them over the time to get not only the TVL at present but also TVL for past days.
withcte_rewardas (selectdate(block_time) as block_date,stake_pool,tx_id,signer,(staking_reward/1e9 )as amountfrom tl_solana.liquid_stakingwhere instruction_type in ('UpdateDeactivated','UpdateActive') ),cte_depositas (selectdate(block_time) as block_date,stake_pool,tx_id,signer, case when instruction_type in ('Deposit','DepositSol','DepositStake') then amount/1e9 else -amount/1e9 end as amount
from tl_solana.liquid_staking where instruction_type in ('Claim','LiquidUnstake','Deposit','WithdrawStake','WithdrawSol','DepositSol','DepositStake')
),cte_deposit_stakeas (select a.block_date,stake_pool,tx_id,signer,amount*sol as amountfrom (selectdate(block_time) as block_date,stake_pool,tx_id,signer,mint_amount/1e9 as amountfrom tl_solana.liquid_stakingwhere instruction_type in ('DepositStakeAccount') )ajoin (select a.block_date,b.price_in_usd /a.price_in_usd as solfrom (select*from tl_solana.priceswhere mint='mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So' )ajoin (select*from tl_solana.priceswhere mint='So11111111111111111111111111111111111111112' )b on a.block_date=b.block_date )bon a.block_date=b.block_date ) select block_date, stake_pool,amount,transfer,wallet,unique_wallet,sum(amount)over(partitionby stake_pool order by block_date) as tvl,sum(unique_wallet)over( order by block_date) as cumulative_wallets,sum(unique_wallet)over(partitionby stake_pool order by block_date) as cumulative_wallets_by_pool,sum(transfer)over(partitionby stake_pool order by block_date) as cumulative_transfer_pool,sum(transfer)over( order by block_date) as cumulative_transferfrom(select block_date, casewhen stake_pool='8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC'then'Marinade'when stake_pool='stk9ApL5HeVAwPLr3TLhDXdZS8ptVu7zp6ov8HFDuMi'then'Sol blaze'when stake_pool='Jito4APyf642JPZPx3hGc6WWJ8zPKtRbRs4P815Awbb'then'Jito'when stake_pool='CtMyWsrUtAwXWiGr9WjHT5fC3p3fgV8cyGpLTo2LJzG1'then'Jpool'--when stake_pool='7ge2xKsZXmqPxa3YmXxXmzCp9Hc2ezrTxh6PECaxCwrL' then 'Daosol'when stake_pool='CgntPoLka5pD5fesJYhGmUCF8KU1QS1ZmZiuAuMZr2az'then'Cogent crypto'when stake_pool='2qyEeSAWKfU18AFthrF7JA8z8ZCi1yt76Tqs917vwQTV'then'LaineSOL'when stake_pool='DqhH94PjkZsjAqEze2BEkWhFQJ6EyU6MdtMphMgnXqeK'then'Marginfi'elsenullendas stake_pool,count(distinct tx_id) astransfer,count(signer) as wallet,count(casewhen rn=1then signer end) as unique_wallet,sum(amount) as amountfrom ( select*,row_number()over(partitionby signer order by block_date) as rn from (select*from cte_depositunion allselect*from cte_rewardunion allselect*from cte_deposit_stake ) )group by1,2 )where stake_pool is not nullorder by1desc
With that we can analyse trends of TVL over time and can also judge the health of any pool or platform
Here is the link to the detailed dashboard for your reference -