Steem for script kiddies: SBD debt ratio

As we all may have noticed, reward distributions switched from SBD to STEEM over the weekend. The reason for this was originally described almost six years ago in the post, Steem Dollar Stability Enhancements, and the current thresholds were apparently set in HF20, as follows:

#define STEEM_SBD_STOP_PERCENT_HF20 (10STEEM_1_PERCENT ) // Stop printing SBD at 10% Market Cap
#define STEEM_SBD_START_PERCENT_HF20 (9STEEM_1_PERCENT) // Start reducing printing of SBD at 9% Market Cap



More recently, it was described again by @fredquantum, in Debt Ratio's impact on the Authors' Rewards on Steem- Understanding the Current Situation.

So, in short, when the ratio of market caps for SBD / STEEM reaches nine percent, the blockchain slows its rate of printing new debt in the form of SBD, and when that ratio reaches 10%, it stops completely. Over the week-end, with the drop in the price of STEEM, we crossed both the 9 and 10 percent thresholds.

image.png

Pixabay license, source

I was curious, however about the actual calculation, so last night I slapped together a little script to try to display the current debt ratio at the command line. If I picked the right blockchain parameters, here's a bash script that produces the desired output.

Update: With help from @moecki in a comment conversation, we were able to identify the specific code that does the calculation, and I changed the script to match. The following script has been updated accordingly (along with comments to remind me where the formula came from):

In brief, the previous version had a rounding error in the fourth digit after the decimal point, and it was also using a different parameter as the source of the price. End update

Update 2: Today I noticed a difference in the way that median prices are reporting from api.steemit.com vs. api.steemitdev.com. The script and sample output below have been updated again to work with both reporting methods.


#!/bin/bash

STEEM_API="https://api.steemit.com"
export STEEM_API
export LC_ALL=C.UTF-8

DYNPROPS=$( curl -s --data '{"jsonrpc":"2.0", "method":"condenser_api.get_dynamic_global_properties", "params":[], "id":1}' ${STEEM_API} )
IRC1=${?}
ERRCODE1=$(echo ${DYNPROPS} | jq -Sr .error.code)

PRICE_FEED=$( curl -s --data '{"jsonrpc":"2.0", "method":"condenser_api.get_feed_history", "params":[], "id":1}' ${STEEM_API} )
IRC2=${?}
ERRCODE2=$(echo ${PRICE_FEED} | jq -Sr .error.code)

export DYNPROPS PRICE_FEED IRC1 IRC2 ERRCODE1 ERRCODE2

if [ ${IRC1} -eq 0 -a ${IRC2} -eq 0 -a "${ERRCODE1}x" == "nullx" -a "${ERRCODE2}x" == "nullx" ]
then
   STEEM_SUPPLY=$(echo ${DYNPROPS} | jq -Sr .result.virtual_supply | awk '{print $1}')
   SBD_SUPPLY=$(echo ${DYNPROPS} | jq -Sr .result.current_sbd_supply | awk '{print $1}')
   SBD_START_PERCENT=$(echo ${DYNPROPS} | jq -Sr .result.sbd_start_percent | awk '{print $1}')
   SBD_STOP_PERCENT=$(echo ${DYNPROPS} | jq -Sr .result.sbd_stop_percent | awk '{print $1}')
   BASE=$(echo ${PRICE_FEED} | jq -Sr .result.current_median_history.base | awk '{print $1}')
   QUOTE=$(echo ${PRICE_FEED} | jq -Sr .result.current_median_history.quote | awk '{print $1}')
   PRICE=$(echo ${BASE} ${QUOTE} | awk '{print $1 / $2}')
   STEEMCAP=$(echo ${STEEM_SUPPLY} ${PRICE} | awk '{printf "%12d", $1 * $2}')
   BC_PRINT_RATE=$(echo ${DYNPROPS} | jq -Sr .result.sbd_print_rate)
   POSTHF21_RATIO=$(echo ${SBD_SUPPLY} ${STEEMCAP} | awk '{ printf "%d", ( $1 * 10000 + $2 / 2 ) / $2 }')
   # PREHF21_RATIO=$(echo ${SBD_SUPPLY} ${STEEMCAP} | awk '{print $1 * 10000 / $2}')

   if [ ${POSTHF21_RATIO} -lt ${SBD_START_PERCENT} ]
   then
      SBD_PRINT_RATE=1
   elif [ ${POSTHF21_RATIO} -gt ${SBD_STOP_PERCENT} ]
   then
      SBD_PRINT_RATE=0
   else
      SBD_PRINT_RATE=$( echo ${SBD_STOP_PERCENT} ${POSTHF21_RATIO} | awk '{print $1 - $2}' )
   fi
   # Convert integer to float
   SBD_PRINT_RATE=$( echo ${SBD_PRINT_RATE} | awk '{print $1 / 100}')
   POSTHF21_RATIO=$( echo ${POSTHF21_RATIO} | awk '{print $1 / 10000}')

   echo "Price: $" ${PRICE}
   printf "STEEM supply: %'.0f\n" ${STEEM_SUPPLY}
   printf "SBD supply (cap): %'.0f\n" ${SBD_SUPPLY}
   printf "STEEM Market Cap (calculated): %'.0f\n" ${STEEMCAP}
   echo ${POSTHF21_RATIO} | awk '{printf "SBD supply (cap) / STEEM CAP: %'\''0.4f\n", $1}'
   echo "SBD print rate: ${SBD_PRINT_RATE} (calculated), ${BC_PRINT_RATE} (queried)"
   # echo ${PREHF21_RATIO} | awk '{printf "SBD supply (cap) / STEEM CAP: %'\''0.4f\n", $1}'
   exit 0
else
   echo "Error encountered: curl returned: ${IRC1}:${IRC2}"
   if [ ${IRC1} -eq 0 -a ${IRC2} -eq 0 ]
   then
      if [ "${ERRCODE1}x" != "nullx" ]
      then
         echo get_dynamic_global_properities - json error code: ${ERRCODE1}.
      fi
      if [ "${ERRCODE2}x" != "nullx" ]
      then
         echo get_current_price_feed - json error code: ${ERRCODE2}.
      fi
   fi
   exit 1
fi


And here's some sample output:

$ ./sbd_ratio.sh
Price: $ 0.250828
STEEM supply: 451556673
SBD supply (cap): 11326327
STEEM Market Cap (calculated): 113263057
SBD supply (cap) / STEEM CAP: 0.1000
SBD print rate: 0 (calculated), 0 (queried)



So, if I picked the right values, the current ratio of the SBD market cap / STEEM market cap is 9.9%, and the blockchain should be printing a mix of STEEM and SBD for author rewards. If I click on details for a pending post, it is consistent with that result.

image.png

The above script has been tested in ubuntu and SUSE linux, including under WSL. "curl" and "jq" are required. Feel free to copy it, modify it, and use it to keep an eye on the blockchain's debt ratio. Of course, also let me know if you see any problems.

Here's a challenge for anyone reading. During the next week or two, write a command line script in any language to answer a simple question of your choosing about the blockchain and show it off in a post to instruct others in how to query the blockchain.

Previously in Steem for script kiddies, I posted:

H2
H3
H4
3 columns
2 columns
1 column
36 Comments