@@ -29,28 +29,43 @@ import { fetchEncodedSysvarAccount, SYSVAR_EPOCH_REWARDS_ADDRESS } from './sysva
29
29
type SysvarEpochRewardsSize = 81 ;
30
30
31
31
/**
32
- * The `EpochRewards` sysvar.
32
+ * Tracks whether the rewards period (including calculation and distribution) is in progress, as
33
+ * well as the details needed to resume distribution when starting from a snapshot during the
34
+ * rewards period.
33
35
*
34
- * Tracks the progress of epoch rewards distribution. It includes:
35
- * - Total rewards for the current epoch, in lamports.
36
- * - Rewards for the current epoch distributed so far, in lamports.
37
- * - Distribution completed block height, i.e. distribution of all staking rewards for the current
38
- * epoch will be completed at this block height.
39
- *
40
- * Note that `EpochRewards` only lasts for a handful of blocks at the start of
41
- * an epoch. When all rewards have been distributed, the sysvar is deleted.
42
- * See https://github.com/anza-xyz/agave/blob/e0203f22dc83cb792fa97f91dbe6e924cbd08af1/docs/src/runtime/sysvars.md?plain=1#L155-L168
36
+ * The sysvar is repopulated at the start of the first block of each epoch. Therefore, the sysvar
37
+ * contains data about the current epoch until a new epoch begins.
43
38
*/
44
39
export type SysvarEpochRewards = Readonly < {
40
+ /** Whether the rewards period (including calculation and distribution) is active */
45
41
active : boolean ;
42
+ /** The rewards currently distributed for the current epoch, in {@link Lamports} */
46
43
distributedRewards : Lamports ;
44
+ /** The starting block height of the rewards distribution in the current epoch */
47
45
distributionStartingBlockHeight : bigint ;
46
+ /**
47
+ * Number of partitions in the rewards distribution in the current epoch, used to generate an
48
+ * `EpochRewardsHasher`
49
+ */
48
50
numPartitions : bigint ;
51
+ /**
52
+ * The {@link Blockhash} of the parent block of the first block in the epoch, used to seed an
53
+ * `EpochRewardsHasher`
54
+ */
49
55
parentBlockhash : Blockhash ;
56
+ /**
57
+ * The total rewards points calculated for the current epoch, where points equals the sum of
58
+ * (delegated stake * credits observed) for all delegations
59
+ */
50
60
totalPoints : bigint ;
61
+ /** The total rewards for the current epoch, in {@link Lamports} */
51
62
totalRewards : Lamports ;
52
63
} > ;
53
64
65
+ /**
66
+ * Returns an encoder that you can use to encode a {@link SysvarEpochRewards} to a byte array
67
+ * representing the `EpochRewards` sysvar's account data.
68
+ */
54
69
export function getSysvarEpochRewardsEncoder ( ) : FixedSizeEncoder < SysvarEpochRewards , SysvarEpochRewardsSize > {
55
70
return getStructEncoder ( [
56
71
[ 'distributionStartingBlockHeight' , getU64Encoder ( ) ] ,
@@ -63,6 +78,10 @@ export function getSysvarEpochRewardsEncoder(): FixedSizeEncoder<SysvarEpochRewa
63
78
] ) as FixedSizeEncoder < SysvarEpochRewards , SysvarEpochRewardsSize > ;
64
79
}
65
80
81
+ /**
82
+ * Returns a decoder that you can use to decode a byte array representing the `EpochRewards`
83
+ * sysvar's account data to a {@link SysvarEpochRewards}.
84
+ */
66
85
export function getSysvarEpochRewardsDecoder ( ) : FixedSizeDecoder < SysvarEpochRewards , SysvarEpochRewardsSize > {
67
86
return getStructDecoder ( [
68
87
[ 'distributionStartingBlockHeight' , getU64Decoder ( ) ] ,
@@ -75,6 +94,12 @@ export function getSysvarEpochRewardsDecoder(): FixedSizeDecoder<SysvarEpochRewa
75
94
] ) as FixedSizeDecoder < SysvarEpochRewards , SysvarEpochRewardsSize > ;
76
95
}
77
96
97
+ /**
98
+ * Returns a codec that you can use to encode from or decode to {@link SysvarEpochRewards}
99
+ *
100
+ * @see {@link getSysvarEpochRewardsDecoder }
101
+ * @see {@link getSysvarEpochRewardsEncoder }
102
+ */
78
103
export function getSysvarEpochRewardsCodec ( ) : FixedSizeCodec <
79
104
SysvarEpochRewards ,
80
105
SysvarEpochRewards ,
@@ -84,17 +109,8 @@ export function getSysvarEpochRewardsCodec(): FixedSizeCodec<
84
109
}
85
110
86
111
/**
87
- * Fetch the `EpochRewards` sysvar.
88
- *
89
- * Tracks the progress of epoch rewards distribution. It includes:
90
- * - Total rewards for the current epoch, in lamports.
91
- * - Rewards for the current epoch distributed so far, in lamports.
92
- * - Distribution completed block height, i.e. distribution of all staking rewards for the current
93
- * epoch will be completed at this block height.
94
- *
95
- * Note that `EpochRewards` only lasts for a handful of blocks at the start of
96
- * an epoch. When all rewards have been distributed, the sysvar is deleted.
97
- * See https://github.com/anza-xyz/agave/blob/e0203f22dc83cb792fa97f91dbe6e924cbd08af1/docs/src/runtime/sysvars.md?plain=1#L155-L168
112
+ * Fetch the `EpochRewards` sysvar account using any RPC that supports the
113
+ * {@link GetAccountInfoApi}.
98
114
*/
99
115
export async function fetchSysvarEpochRewards (
100
116
rpc : Rpc < GetAccountInfoApi > ,
0 commit comments