Skip to content

Instantly share code, notes, and snippets.

@ochaloup
Last active June 6, 2024 07:40
Show Gist options
  • Save ochaloup/7ddb3e054e3a383aa7e20d828d1e3ae2 to your computer and use it in GitHub Desktop.
Save ochaloup/7ddb3e054e3a383aa7e20d828d1e3ae2 to your computer and use it in GitHub Desktop.
Loading data about mint pubkey for the SPL Pool program
#!/bin/bash
# Using different scripts from the gist
# bintodec.sh
# - https://discord.com/channels/@me/1017776053873287258/1247924569319149649
# arraybyindex.sh
# - https://gist.github.com/ochaloup/4d6ca93a6826a65c3f1f781d5af59d4b
# tobase58.py
# - https://discord.com/channels/@me/1017776053873287258/1247924569319149649
# This script works with SPL Pool program
# https://github.com/solana-labs/solana-program-library/blob/master/stake-pool/program/src/state.rs#L32
# pub account_type: AccountType, | 0
# pub manager: Pubkey, | 1
# pub staker: Pubkey, | 33
# pub stake_deposit_authority: Pubkey, | 65
# pub stake_withdraw_bump_seed: u8, | 66
# pub validator_list: Pubkey, | 98
# pub reserve_stake: Pubkey, | 130
# pub pool_mint: Pubkey, | 162
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <file with list of accounts>"
exit 1
fi
FILE=$1
if [ ! -e "$FILE" ]; then
echo "File $FILE does not exist"
exit 2
fi
for I in `cat $FILE`; do
# data clean, format of data is '<empty spaces>"<pubkey>"<something>'
SPL_POOL_ACCOUNT=$(echo $I | sed 's/^[ \t]*"//g' | sed 's/".*//g')
echo "Loading Solana account $SPL_POOL_ACCOUNT"
OUT_FILE="/tmp/${SPL_POOL_ACCOUNT}.bin"
solana account -um $SPL_POOL_ACCOUNT -o "$OUT_FILE"
ARR=$(bintodec.sh "$OUT_FILE")
MINT_PUBKEY_ARR=$(arraybyindex.sh $ARR 162 32)
MINT_PUBKEY=$(tobase58.py $MINT_PUBKEY_ARR)
echo "SPL pool: $SPL_POOL_ACCOUNT, mint: $MINT_PUBKEY"
solana account -um $MINT_PUBKEY 2>&1 > /dev/null
[ $? -ne 0 ] && echo "Mint $MINT_PUBKEY does not exist" && exit 3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment