Steem for script kiddies: SBD debt ratio

in #steem2 years ago (edited)

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.


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 vs. The script and sample output below have been updated again to work with both reporting methods.


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} )
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} )
ERRCODE2=$(echo ${PRICE_FEED} | jq -Sr .error.code)


if [ ${IRC1} -eq 0 -a ${IRC2} -eq 0 -a "${ERRCODE1}x" == "nullx" -a "${ERRCODE2}x" == "nullx" ]
   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} ]
   elif [ ${POSTHF21_RATIO} -gt ${SBD_STOP_PERCENT} ]
      SBD_PRINT_RATE=$( echo ${SBD_STOP_PERCENT} ${POSTHF21_RATIO} | awk '{print $1 - $2}' )
   # 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
   echo "Error encountered: curl returned: ${IRC1}:${IRC2}"
   if [ ${IRC1} -eq 0 -a ${IRC2} -eq 0 ]
      if [ "${ERRCODE1}x" != "nullx" ]
         echo get_dynamic_global_properities - json error code: ${ERRCODE1}.
      if [ "${ERRCODE2}x" != "nullx" ]
         echo get_current_price_feed - json error code: ${ERRCODE2}.
   exit 1

And here's some sample output:

$ ./
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.


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:


Another excellent example of the use of the scripting language! In "modern" languages, the whole thing is more readable, but also involves a little more effort.

When I looked at the code some time ago, I noticed various constants that I could not yet understand. Among them were the two you mentioned. Now the whole thing is clearer.

Here's a challenge for anyone reading.

I will think about it. :-))

Sir please help me how to grow my steemit account please help me

Note on Update 2:
The first line of the new script does not seem to belong there. :-)
The printf commands throw an error if the locale settings contain a different formatting (e.g. de_DE.utf8).
This can be solved with an export LC_ALL=C.UTF-8 after the export STEEM_API.

Thanks! Updated.

Awesome! I have read a few studies earlier from different sources and the market cap as derived from the products of supply and price was used for the calculation. But I noticed something, during those times, the SBD price was either $1 or below, or both assets had nearly equal market prices (For example; SBD = $3.2 and Steem = $3.32). With this piece, on the Steem blockchain, it is assumed that SBD maintains the peg of $1 and that would be utilized for the debt ratio. Great work and thanks, @remlaps-lite.

With this piece, on the Steem blockchain, it is assumed that SBD maintains the peg of $1 and that would be utilized for the debt ratio.

Thanks for the reply! From the blockchain's perspective, I think the price of SBD is always 1 USD because that's what it has to pay (in STEEM) if people make use of the built in SBD -> STEEM conversion function. I'm pretty sure that it uses $1 in its debt ratio calculation, since that percentage matches what we're seeing with partial payouts right now, but I didn't find the relevant section of code, yet. I might do some more looking again this weekend.

I guess the code for the calculation of the print rate should be there:


Thanks again for the link. It looks like that got it. Before work this morning, I updated the script to calculate the SBD print rate and display it side by side with the value stored in the blockchain.

$ ./
Price: $ 0.267
STEEM supply: 448147324
SBD supply (cap): 11295999
STEEM Market Cap (calculated): 119655335
SBD supply (cap) / STEEM CAP: 0.0944
SBD print rate: 0.56 (calculated), 5600 (queried)

That's a perfect result! :-)
However, it is still not clear to me why 0.5 was not added directly.

Agreed. I'm assuming the original calculation was just a programming error.

You are right, it's quite obvious that $1 is the price considered on the blockchain which makes its supply equivalent to the market cap and it's eventually used in the calculation of the debt ratio. I look forward to seeing more of your exploits after the weekend if you can. Have a great day, mate.

Good coding from you. It is very effective decision from steem authority to hold up steem and sbd price. This system may be still open since early age of steem blockchain. That's obviously a good decision.

Thanks for the information.

Does that mean that when the Steem exchange rate gets stronger against SBD, the payout in SBD gets bigger too?

At what condition of the Steem exchange rate will the payout be fully in SBD and SP?


Yes, it works backwards, too. It prints more SBDs as it approaches 9% from above and less SBDs as it approaches 10% from below. If it goes below 9% it will stop printing STEEM, and if it goes above 10% it will stop printing SBDs.

Hi @remlaps-lite ,now I understand why steem increases, I looked at it and honestly I thought they were rewards from some contests I participate in, thanks for your information

Yeah, It made it a bit clearer for me too.

Yes, I noticed that too. Since the SBD price is high, it is financially disadvantageous for us. Also another downside. There will be an ever-increasing supply of Steem. The increase in the supply of Steem means the increase in inflation and the decrease in the price of Steem, making it worthless.

Thanks to you, I learned something new with the Steem blockchain. Steem price dropped more than SBD. That's why the SBD/Steem market cap ratio increased. I wondered why such a ratio was chosen.

I can't wait to join the challenge reading.

You have write an awesome code for this ration calculation. SBD has a good stability than any other backed dollar like HBD. I hope decision that has been taken from the authority will make strong this blockchain more.

@gustavomory2 creo que de esto era de lo que estabas hablando. Espero que este post te ayude a entender qué pasó con el SBD. Yo como de costumbre, no entiendo nada. Saludos!

Si es justamente mi preocupación, ahora entiendo, para que tu también entiendas, cuando el programa que sirve para que se genere la cadena de bloques, es decir como los engranajes de una maquina, los estimados del valor del steem con referencia al SBD no son los números exactos, por que no es fácil hacer que coincidan cuando existen fracciones, y al llegar al ciclo exacto que aquí explican es de 10 pero la otra cripto cierra en 9.9 sucede un salto en los cálculos. espero haber podido hacer una explicación por analogía.

Coin Marketplace

STEEM 0.26
TRX 0.10
JST 0.031
BTC 41707.82
ETH 2207.88
USDT 1.00
SBD 5.12