2

the query for current total supply given in the doc doesn't seem to work for me, is off a fraction of a million (according to pooltool.io) and the resulting value keeps rising with time indicating the amount of ADA that is in UTXOs rather than TotalSupply.

How do I query cardano-db-sync for total supply?

---update:

I get that the above query only considers the UTxO set for unspent transaction outputs, to which I should add the rewards which haven't been withdrawn yet.. but I am not sure how to do that as the sum of all withdrawals is bigger than the sum of all rewards given:

cexplorer=# select sum(amount) / 1000000 from reward;    
--------------------
 554006568

cexplorer=# select sum(amount) / 1000000 from withdrawal;    
--------------------
 875322654

shouldn't all rewards given be bigger than all withdrawals?

user3755529
  • 1,050
  • 1
  • 10
  • 30

1 Answers1

1

Thanks to some help I figure out that Withdrawal includes the ITN rewards, and I need to consider Reserve too. The right calculation (from ActiveRecord connecting to db-sync) is as follow:

UtxoView.sum('value') + Reserve.sum('amount') + Reward.sum('amount') - Withdrawal.sum('amount')
   (8495.8ms)  SELECT SUM("utxo_view"."value") FROM "utxo_view"
   (10.9ms)  SELECT SUM("reserve"."amount") FROM "reserve"
   (231.7ms)  SELECT SUM("reward"."amount") FROM "reward"
   (36.5ms)  SELECT SUM("withdrawal"."amount") FROM "withdrawal"
user3755529
  • 1,050
  • 1
  • 10
  • 30