Skip to content

Instantly share code, notes, and snippets.

@Bambarello
Last active October 31, 2024 14:54
Show Gist options
  • Save Bambarello/213089141801416bfa99d388560e9f8b to your computer and use it in GitHub Desktop.
Save Bambarello/213089141801416bfa99d388560e9f8b to your computer and use it in GitHub Desktop.

Utils collection

Check next epoch stake

curl -sL https://gist.githubusercontent.com/AGx10k/e001f79e64a2440c406e9d0839ea0698/raw/sol_stake_next.sh | bash -s -- $(solana-keygen pubkey $HOME/solana/vote-account-keypair.json)

Check vote balance

solana balance $HOME/solana/vote-account-keypair.json

Withdraw rewards AUTO - from vote to validator and transfer to your external wallet

wget https://gist.githubusercontent.com/Bambarello/213089141801416bfa99d388560e9f8b/raw/sol_withdraw.sh

setup the min balance on the validator acc, setup the wallet for withdrawal.

curl -sL https://gist.githubusercontent.com/Bambarello/213089141801416bfa99d388560e9f8b/raw/sol_withdraw.sh | bash -s -- {{ADDRESS_TO_WITHDRAW}}

Withdraw rewards TO VALIDATOR ONLY

curl -sL https://gist.githubusercontent.com/Bambarello/213089141801416bfa99d388560e9f8b/raw/withdraw-to-val.sh | bash -s -- {{AMOUNT_TO_WITHDRAW}}

List stakes on your validator (all on validator)

curl -sL https://gist.githubusercontent.com/Bambarello/213089141801416bfa99d388560e9f8b/raw/sol_list_stakes.sh | bash -s --

Update with fresh snapshot

  • and use --no-snapshot-fetch in your validator config

curl -sL https://gist.githubusercontent.com/Bambarello/213089141801416bfa99d388560e9f8b/raw/update.sh | bash -s -- v1.4.27

screen bash -c "sleep $(shuf -i 10-100 -n 1) && solana-install init 1.5.8 && grep -m1 'snapshot-' < <(inotifywait -m -e moved_to /root/solana/validator-ledger/) && systemctl daemon-reload && service solana restart && journalctl -u solana -f --no-hostname

while true; do time solana catchup /root/solana/validator-keypair.json http://127.0.0.1:8899/; sleep 15; done"

Solana Slots before Update

curl -sL https://gist.githubusercontent.com/AGx10k/cf764fc3296e6b277e4b4177e918b816/raw/solana-slots-to-update.sh | bash -s --

#!/bin/bash
OUT=$(solana stakes $HOME/solana/vote-account-keypair.json --output json)
#LEDGER_ADDRESS=
#STAKES=$(echo "$OUT" | jq -r --arg LEDGER_ADDRESS "$LEDGER_ADDRESS" '[ .[] | select(.withdrawer == $LEDGER_ADDRESS) ]')
STAKES=$OUT
for row in $(echo "${STAKES}" | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
stakePubkey=$(_jq '.stakePubkey')
accountBalance=$(($(_jq '.accountBalance')/1000000000))
delegatedStake=$(($(_jq '.delegatedStake')/1000000000))
unixTimestamp=$(_jq '.unixTimestamp')
releaseDate=$(date -d @$unixTimestamp 2>/dev/null || date -r $unixTimestamp 2>/dev/null)
echo "$stakePubkey $accountBalance SOL, delegated: $delegatedStake SOL release: $releaseDate"
done
#!/bin/bash
BIN_FILE="/root/.local/share/solana/install/active_release/bin/solana"
KEYS_FILE="$HOME/solana/validator-keypair.json"
#URL="http://127.0.0.1:8899"
URL="https://api.mainnet-beta.solana.com"
WALLET=$1
TX=$2
if [[ $(bc -l <<< "$TX>0") -eq 1 ]]; then
echo "Let's transfer $REWARD to $WALLET"
$BIN_FILE transfer -k $KEYS_FILE $WALLET $TX --url=$URL
else
echo "Tx is $REWARD"
fi
echo "DONE"
sleep 5
echo BALANCE
solana balance
#!/bin/bash
BIN_FILE="/root/.local/share/solana/install/active_release/bin/solana"
KEYS_FILE="$HOME/solana"
URL="http://127.0.0.1:8899"
MIN_BALANCE=8
WALLET=$1
$BIN_FILE withdraw-from-vote-account $KEYS_FILE/vote-account-keypair.json $KEYS_FILE/validator-keypair.json ALL --authorized-withdrawer $KEYS_FILE/vote-account-keypair.json --url=$URL
VOTE_BALANCE=$($BIN_FILE balance -k $KEYS_FILE/vote-account-keypair.json --url=$URL | awk '{print $1}')
echo -e "Vote Balance: $VOTE_BALANCE"
BALANCE=$($BIN_FILE balance -k $KEYS_FILE/validator-keypair.json --url=$URL | awk '{print $1}')
echo -e "Identity Balance: $BALANCE"
REWARD=$(echo "$BALANCE-$MIN_BALANCE" | bc)
if [[ $(bc -l <<< "$REWARD>0") -eq 1 ]]; then
echo "Let's withdraw $REWARD of REWARD tokens"
$BIN_FILE transfer -k $KEYS_FILE/validator-keypair.json $WALLET $REWARD --url=$URL
else
echo "Reward is $REWARD"
fi
echo "DONE"
#!/usr/bin/env bash
# /root/update.sh v1.4.27
# and use --no-snapshot-fetch in your validator config
# check your PATH and all paths to /root/validator-ledger below
source ~/.profile > /dev/null 2>&1
BIN_INSTALL=$(which solana-install)
BIN_VALIDATOR=$(which solana-validator)
pkgs='inotify-tools'
if ! dpkg -s $pkgs >/dev/null 2>&1; then
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y $pkgs
fi
if [[ -z $1 ]]; then
echo "Usage: $0 [version]"
exit 1
fi
set -ex
${BIN_INSTALL} init "$@"
sudo systemctl daemon-reload
# grep -m1 'snapshot-' < <(inotifywait -m -e moved_to /root/solana/validator-ledger) && sleep 600
${BIN_VALIDATOR} --ledger ${HOME}/solana/validator-ledger exit --min-idle-time 40 --max-delinquent-stake 15
#sudo systemctl --no-pager status solana
#sudo journalctl -u solana -f --no-hostname | grep solana | grep -v solana_metrics
#!/usr/bin/env bash
# /root/update.sh v1.16.25
# and use --no-snapshot-fetch in your validator config
# check your PATH and all paths to /root/validator-ledger below
source ~/.profile > /dev/null 2>&1
BIN_INSTALL=$(which solana-install)
BIN_VALIDATOR=$(which solana-validator)
if [[ -z $1 ]]; then
echo "Usage: $0 [version]"
exit 1
fi
set -ex
${BIN_INSTALL} init "$@"
sudo systemctl daemon-reload
${BIN_VALIDATOR} --ledger ${HOME}/solana/validator-ledger wait-for-restart-window --min-idle-time 30 --max-delinquent-stake 15 --skip-new-snapshot-check
mkdir ${HOME}/solana/validator-ledger/remote || true
RPC="https://api.mainnet-beta.solana.com"
curl -s https://raw.githubusercontent.com/c29r3/solana-snapshot-finder/main/snapshot-finder.py --output ${HOME}/snapshot-finder.py
python3 ${HOME}/snapshot-finder.py --snapshot_path ${HOME}/solana/validator-ledger/remote/ --measurement_time 10 --min_download_speed 80 --max_latency 120 --max_snapshot_age 800 -r ${RPC}
systemctl restart solana
#!/usr/bin/env bash
# /root/update.sh v1.4.27
# and use --no-snapshot-fetch in your validator config
# check your PATH and all paths to /root/validator-ledger below
source ~/.profile > /dev/null 2>&1
BIN_INSTALL=$(which solana-install)
BIN_VALIDATOR=$(which solana-validator)
pkgs='inotify-tools'
if ! dpkg -s $pkgs >/dev/null 2>&1; then
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y $pkgs
fi
if [[ -z $1 ]]; then
echo "Usage: $0 [version]"
exit 1
fi
VER="$@"
set -ex
sh -c "$(curl -sSfL https://release.jito.wtf/${VER}-jito/install)"
sudo systemctl daemon-reload
${BIN_VALIDATOR} --ledger ${HOME}/solana/validator-ledger exit --min-idle-time 20 --max-delinquent-stake 15
#!/usr/bin/env bash
# /root/update.sh v1.18.9
# and remove --no-snapshot-fetch in your validator config
# check your PATH and all paths to /root/validator-ledger below
source ~/.profile > /dev/null 2>&1
BIN_INSTALL=$(which agave-install)
BIN_VALIDATOR=$(which agave-validator)
ledger=$(find /dev/shm/ ${HOME}/solana/ /mnt/ -name admin.rpc | sed -E 's|/[^/]+$|/|')
pkgs='inotify-tools'
if ! dpkg -s $pkgs >/dev/null 2>&1; then
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install -y $pkgs
fi
if [[ -z $1 ]]; then
echo "Usage: $0 [version]"
exit 1
fi
set -ex
${BIN_INSTALL} init "$@"
sudo systemctl daemon-reload
# grep -m1 'incremental-snapshot-' < <(inotifywait -m -e moved_to /dev/shm/validator-ledger) && sudo systemctl restart solana
${BIN_VALIDATOR} --ledger $ledger exit --min-idle-time 15 --max-delinquent-stake 15
# sudo systemctl daemon-reload && sudo systemctl restart solana
#!/bin/bash
# input vars #
VOTE_KEY_NAME="vote-account-keypair.json"
VAL_KEY_NAME="validator-keypair.json"
WITHDRAW_AUTH="authority-keypair.json"
#amount num or ALL
#AMOUNT=$1
VOTE_MIN_BALANCE="1"
# calc vars
SCRIPT_DIR=`cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P`
APP_SOLANA=`which solana`
APP_SOLANA_KEYGEN=`which solana-keygen`
VOTE_KEYS_PATH=$(find $HOME -iname ${VOTE_KEY_NAME} | head -n 1)
VAL_KEYS_PATH=$(find $HOME -iname ${VAL_KEY_NAME} | head -n 1)
WITHDRAW_KEYS_PATH=$(find $HOME -iname ${WITHDRAW_AUTH} | head -n 1)
VOTE_PUBKEY=`${APP_SOLANA_KEYGEN} pubkey ${VOTE_KEYS_PATH}`
VAL_PUBKEY=`${APP_SOLANA_KEYGEN} pubkey ${VAL_KEYS_PATH}`
VOTE_BALANCE=$($APP_SOLANA balance -k ${VOTE_KEYS_PATH} | awk '{print $1}')
VOTE_BALANCE=$(bc -l <<< "$VOTE_BALANCE - $VOTE_MIN_BALANCE")
#VOTE_BALANCE=${AMOUNT}
$APP_SOLANA withdraw-from-vote-account ${VOTE_PUBKEY} ${VAL_PUBKEY} ${VOTE_BALANCE} --authorized-withdrawer ${WITHDRAW_KEYS_PATH} --url http://127.0.0.1:8899
echo "DONE"
#!/bin/bash
BIN_FILE="/root/.local/share/solana/install/active_release/bin/solana"
KEYS_FILE="$HOME/solana"
URL="http://127.0.0.1:8899"
WITHDRAW_BALANCE=$1
$BIN_FILE withdraw-from-vote-account $KEYS_FILE/vote-account-keypair.json $KEYS_FILE/validator-keypair.json $WITHDRAW_BALANCE --authorized-withdrawer $KEYS_FILE/vote-account-keypair.json --url=$URL
VOTE_BALANCE=$($BIN_FILE balance -k $KEYS_FILE/vote-account-keypair.json --url=$URL | awk '{print $1}')
echo -e "Vote Balance: $VOTE_BALANCE"
BALANCE=$($BIN_FILE balance -k $KEYS_FILE/validator-keypair.json --url=$URL | awk '{print $1}')
echo -e "Identity Balance: $BALANCE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment