Skip to content

Instantly share code, notes, and snippets.

@sv3t0sl4v
Last active March 1, 2022 18:47
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sv3t0sl4v/28f896752edc9e20347ffc6d8cefe74c to your computer and use it in GitHub Desktop.
Save sv3t0sl4v/28f896752edc9e20347ffc6d8cefe74c to your computer and use it in GitHub Desktop.
Automatically Update GLM Node Prices With Cron (Linux)
#!/bin/bash
PATH="$HOME/.local/bin:$PATH"
#====================================================================================================================
# Created by svet0slav of Countess Cat Inc - https://countesscat.com
# TODO: take into account GLM token price, node power draw and electricity price to improve price adjustments
# open to suggestions
#====================================================================================================================
# UPDATE GLM NODE PRICES
# GLM node not getting tasks and not earning you anything? No problem!
# This script checks the median of the prices on the golem.network and updates all 3 values related to price:
# - price for CPU per hour
# - price for working environment per hour
# - price for starting a task
# It also checks what percent of the nodes are actually doing work and assigns that much percent to the median price.
# Expected result: GLM nodes will get more and more taks, because your price is OK compared what other providers do.
# Feel free to run a chmod +x on it and run on an hourly basis with cron. This way your nodes get more tasks.
# In your crontab for your user running golemsp add the command
# @hourly /path/to/auto_update_GLM_node_prices.sh
#====================================================================================================================
# REQUIRES jq so run the command below to install it
# sudo apt -y install jq
#====================================================================================================================
# DONATIONS
# Accepting GLM donations, if you liked the script.
# WALLET: 0x2b33250ace192caC4Fc0D7c720cfc61b6BBd920F
# NETWORK: POLYGON MAINNET
#====================================================================================================================
# CUSTOM SETTINGS
#====================================================================================================================
VAL_computing=$(curl -s 'https://api.stats.golem.network/v1/network/computing' | jq -r '(.computing_now | tonumber)')
VAL_total=$(curl -s 'https://api.stats.golem.network/v1/network/online' | jq length)
VAL_percent="$(echo "$VAL_computing" "$VAL_total" |awk '{printf "%.2f", $1 / $2}')"
GET_cpuhour=$(curl -s 'https://api.stats.golem.network/v1/network/pricing/median' | jq -r '(.cpuhour | tonumber)')
GET_perhour=$(curl -s 'https://api.stats.golem.network/v1/network/pricing/median' | jq -r '(.perhour | tonumber)')
GET_start=$(curl -s 'https://api.stats.golem.network/v1/network/pricing/median' | jq -r '(.start | tonumber)')
VAL_cpuhour="$(echo "$GET_cpuhour" "$VAL_percent" |awk '{printf "%.18f", $1 * $2}')"
VAL_perhour="$(echo "$GET_perhour" "$VAL_percent" |awk '{printf "%.18f", $1 * $2}')"
VAL_start="$(echo "$GET_start" "$VAL_percent" |awk '{printf "%.18f", $1 * $2}')"
#====================================================================================================================
# METHODS
#====================================================================================================================
function SET_cpuhour() {
echo "Setting price for CPU per hour to $VAL_cpuhour"
golemsp settings set --cpu-per-hour $VAL_cpuhour
echo "Done!"
}
function SET_perhour() {
echo "Setting price for working environment per hour to $VAL_perhour"
golemsp settings set --env-per-hour $VAL_perhour
echo "Done!"
}
function SET_start() {
echo "Setting price for starting a task to $VAL_start"
golemsp settings set --starting-fee $VAL_start
echo "Done!"
}
function hr() {
printf '=%.0s' {1..100}
printf "\n"
}
#====================================================================================================================
# RUN SCRIPT
#====================================================================================================================
hr
SET_cpuhour
hr
SET_perhour
hr
SET_start
hr
printf "GLM node prices updated!\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment