1

I run a validator and have a delegator asking how to see lifetime rewards earnings for his stake account.

I have used solana stakes --withdraw-authority <wallet pubkey> to show stake account pubkeys associated with his wallet, and then used solana inflation rewards <stake account pubkey> to show the rewards for that stake account (current epoch) and add the flag --rewards-epoch xxx to show a specific epoch reward.

However, I would like to see the lifetime earnings of that stake account since it was delegated to my validator. Can this be done?

3 Answers 3

0

solana inflation reward uses the getInflationReward RPC call under the hood https://docs.solana.com/api/http#getinflationreward, which only gives rewards for one epoch at a time.

If you wanted to, however, you could easily change the CLI to iterate from the current epoch all the way down. Here's the source in case you ever want to do it! https://github.com/solana-labs/solana/blob/2613ad7d70cf0f469f5ed59d94f615b7798cc666/cli/src/inflation.rs#L100

Or you could write a wrapper shell script like:

current_epoch=$(solana epoch-info --output json-compact | jq .epoch)
end_epoch=100 # tune to taste
for i in $(seq $current_epoch -1 $end_epoch);
do
    solana inflation rewards --rewards-epoch $i ...
done
1
  • Thanks @Jon C, this give me more elegant way to do what I was already able to do...get each epoch rewards. But what I need to do is find a way to aggregate each epoch into a total lifetime rewards. Appreciate your time though!
    – T3chie
    Commented Apr 15, 2023 at 12:25
0

Given that you're only interested in the net and not the per-epoch amounts, you can simply subtract the current stake account balance from the balance when they first delegated the account (assuming they're still delegated to you).

The output from the below command will tell you the activation epoch:

$ solana stake-account SOME_ACCOUNT_PUBKEY --output json
{
  ...
  "activationEpoch": X,
  ...
} 

Now that you know the activation epoch, you can find the balance of that account from that epoch. Recall that a delegator won't earn rewards in delegated epoch, so you'll want to use X+1 for the epoch.

$ solana inflation rewards SOME_ACCOUNT_PUBKEY --rewards-epoch X+1 --output json
{
  ...
  "amount": A_0,
  "postBalance": PB_0,
  ...
}

So, the stake account balance in the activation epoch was PB_0 - A_0. Finally, run the same command without an epoch specified, which will default to the latest completed epoch:

$ solana inflation rewards SOME_ACCOUNT_PUBKEY --output json
{
  ...
  "amount": A_1,
  "postBalance": PB_1,
  ...
}

Pulling these all-together, lifetime rewards earnings = PB_1 - PB_0 - A_0.

0

After some trial and error, I came up with a solution to script the process of using solana stake-account and solana inflation rewards to

  1. Determine Activation Epoch
  2. Determine the initial balance of a stake account
  3. Subtract it from the current balance
  4. convert to SOL from Lamports
  5. output total SOL inflation rewards for a stake account

The stake account address to check can be entered in $1 by using ./check-rewards <stake-acct-pubkey>

Example of output:

sol@host:~$ ./check-rewards2.sh <stake-acct-pubkey>

Rewards for <stake-acct-pubkey>
      Activation Epoch = 396
      Current Balance = 1540.917795482 sol

Checking rewards for Epoch 397
   Subtract initial_reward from initial_postbalance to get Initial Balance
      amount_inital_reward = 717566688 lamports
      Initial postBalance Balance 1512717566688 lamports
      Initial Balance = 1512000000000 lamports
      Initial Balance = 1512.000000000 sol

Total Rewards = 28.917795482 sol

Here Is my code...probably could be better...

NC='\033[0m' # No Color
YELLOW='\033[0;33m'
RED='\033[0;31m'
GREEN='\033[1;32m'
MAGENTA='\033[0;35m'
CYAN='\033[1;36m'


# echo stake account
echo -e $RED "\nRewards for $1" $NC



solana stake-account -um $1 --output json > stake_acct.json ;
activation_epoch=$(cat stake_acct.json | grep -E -o ".{0,0}\"activationEpoch\": .{0,3}" |cut -c20-)
current_balance_lamports=$(cat stake_acct.json | grep -E -o ".{0,0}\"accountBalance\": .{0,12}[0-9]" |cut -c19-)

echo -e $CYAN "     Activation Epoch = $activation_epoch" $NC

current_balance_sol=$(expr $current_balance_lamports*0.000000001 | bc)
echo -e $CYAN "     Current Balance = $current_balance_sol sol" $NC

first_reward_epoch=$((activation_epoch+1))

echo -e $RED "\nChecking rewards for Epoch $first_reward_epoch" $NC


solana inflation rewards -um $1 --rewards-epoch $first_reward_epoch --output json > stake_acct_initial_reward.json ;
amount_initial_reward=$(cat stake_acct_initial_reward.json | grep -Eo ".{0,0}\"amount\": .{0,12}[0-9]" |cut -c11-)
#echo "Amount_0 = $A_1 SOL"

echo -e $GREEN "  Subtract initial_reward from initial_postbalance to get Initial Balance" $NC
echo -e $CYAN "     amount_inital_reward = $amount_initial_reward lamports" $NC

post_bal_initial=$(cat stake_acct_initial_reward.json | grep -Eo ".{0,0}\"postBalance\": .{0,12}[0-9]" |cut -c16-)

echo -e $CYAN "     Initial postBalance Balance $post_bal_initial lamports" $NC

true_initial_bal=$(expr $post_bal_initial-$amount_initial_reward | bc)
true_initial_bal_sol=$(expr $true_initial_bal*0.000000001 | bc)

echo -e $CYAN "     Initial Balance = $true_initial_bal lamports" $NC
echo -e $CYAN "     Initial Balance = $true_initial_bal_sol sol" $NC


total_rewards=$(expr $current_balance_sol-$true_initial_bal_sol | bc)

echo -e $YELLOW "     \nTotal Rewards = $total_rewards sol\n" $NC

Example Output

Thanks @steviez for pushing me back here and providing input...maybe it will help someone else...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.