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.
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
#!/bin/bash
STEEM_API="https://api.steemitdev.com"
export STEEM_API
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}')
PRICE=$(echo ${PRICE_FEED} | jq -Sr .result.current_median_history.base | awk '{print $1}')
# PRICE=$(echo ${AMOUNT} | awk '{print $1}')
STEEMCAP=$(echo ${STEEM_SUPPLY} ${PRICE} | awk '{printf "%12d", $1 * $2}')
# See https://steemit.com/steem/@remlaps-lite/steem-for-script-kiddies-sbd-debt-ratio and
# https://github.com/steemit/steem/blob/master/libraries/chain/database.cpp#L3855-L3887
# percent_sbd = uint16_t(
# ( ( fc::uint128_t( ( dgp.current_sbd_supply * get_feed_history().current_median_history ).amount.value )
# * STEEM_100_PERCENT + dgp.virtual_supply.amount.value/2 )
# / dgp.virtual_supply.amount.value ).to_uint64() )
POSTHF21_RATIO=$(echo ${SBD_SUPPLY} ${STEEMCAP} | awk '{ print ( $1 * 10000 + $2 / 2 ) / ( $2 * 10000 )}')
PREHF21_RATIO=$(echo ${SBD_SUPPLY} ${STEEMCAP} | awk '{print $1 / $2}')
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 ${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.253
STEEM supply: 450,120,367
SBD supply (cap): 11,275,957
STEEM Market Cap (calculated): 113,880,452
SBD supply (cap) / STEEM CAP: 0.0990
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.
I will think about it. :-))
Sir please help me how to grow my steemit account please help me
I am making $92 an hour working from home. i was greatly surprised at the same time as my neighbour advised me she changed into averaging $ninety five however I see the way it works now. I experience mass freedom now that I'm my non-public boss.
that is what I do.. https://www.incomehd.com
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 theexport 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.
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: https://github.com/steemit/steem/blob/master/libraries/chain/database.cpp#L3855-L3887.
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.
$ ./sbd_ratio.sh
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?
Thanks
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.