1- import { ContainerType , ValueOf } from "@chainsafe/ssz" ;
21import { ChainForkConfig } from "@lodestar/config" ;
3- import { Epoch , ssz } from "@lodestar/types" ;
4- import { ArrayOf , JsonOnlyReq } from "../../../utils/codecs.js" ;
2+ import { Epoch , rewards } from "@lodestar/types" ;
3+ import { JsonOnlyReq } from "../../../utils/codecs.js" ;
54import { Endpoint , RouteDefinitions , Schema } from "../../../utils/index.js" ;
65import { ExecutionOptimisticAndFinalizedCodec , ExecutionOptimisticAndFinalizedMeta } from "../../../utils/metadata.js" ;
76import { fromValidatorIdsStr , toValidatorIdsStr } from "../../../utils/serdes.js" ;
87import { BlockArgs } from "./block.js" ;
98import { ValidatorId } from "./state.js" ;
109
11- const BlockRewardsType = new ContainerType (
12- {
13- /** Proposer of the block, the proposer index who receives these rewards */
14- proposerIndex : ssz . ValidatorIndex ,
15- /** Total block reward, equal to attestations + sync_aggregate + proposer_slashings + attester_slashings */
16- total : ssz . UintNum64 ,
17- /** Block reward component due to included attestations */
18- attestations : ssz . UintNum64 ,
19- /** Block reward component due to included sync_aggregate */
20- syncAggregate : ssz . UintNum64 ,
21- /** Block reward component due to included proposer_slashings */
22- proposerSlashings : ssz . UintNum64 ,
23- /** Block reward component due to included attester_slashings */
24- attesterSlashings : ssz . UintNum64 ,
25- } ,
26- { jsonCase : "eth2" }
27- ) ;
28-
29- const AttestationsRewardType = new ContainerType (
30- {
31- /** Reward for head vote. Could be negative to indicate penalty */
32- head : ssz . UintNum64 ,
33- /** Reward for target vote. Could be negative to indicate penalty */
34- target : ssz . UintNum64 ,
35- /** Reward for source vote. Could be negative to indicate penalty */
36- source : ssz . UintNum64 ,
37- /** Inclusion delay reward (phase0 only) */
38- inclusionDelay : ssz . UintNum64 ,
39- /** Inactivity penalty. Should be a negative number to indicate penalty */
40- inactivity : ssz . UintNum64 ,
41- } ,
42- { jsonCase : "eth2" }
43- ) ;
44-
45- const IdealAttestationsRewardsType = new ContainerType (
46- {
47- ...AttestationsRewardType . fields ,
48- effectiveBalance : ssz . UintNum64 ,
49- } ,
50- { jsonCase : "eth2" }
51- ) ;
52-
53- const TotalAttestationsRewardsType = new ContainerType (
54- {
55- ...AttestationsRewardType . fields ,
56- validatorIndex : ssz . ValidatorIndex ,
57- } ,
58- { jsonCase : "eth2" }
59- ) ;
60-
61- const AttestationsRewardsType = new ContainerType (
62- {
63- idealRewards : ArrayOf ( IdealAttestationsRewardsType ) ,
64- totalRewards : ArrayOf ( TotalAttestationsRewardsType ) ,
65- } ,
66- { jsonCase : "eth2" }
67- ) ;
68-
69- const SyncCommitteeRewardsType = ArrayOf (
70- new ContainerType (
71- {
72- validatorIndex : ssz . ValidatorIndex ,
73- reward : ssz . UintNum64 ,
74- } ,
75- { jsonCase : "eth2" }
76- )
77- ) ;
78-
79- /**
80- * Rewards info for a single block. Every reward value is in Gwei.
81- */
82- export type BlockRewards = ValueOf < typeof BlockRewardsType > ;
83-
84- /**
85- * Rewards for a single set of (ideal or actual depending on usage) attestations. Reward value is in Gwei
86- */
87- export type AttestationsReward = ValueOf < typeof AttestationsRewardType > ;
88-
89- /**
90- * Rewards info for ideal attestations ie. Maximum rewards could be earned by making timely head, target and source vote.
91- * `effectiveBalance` is in Gwei
92- */
93- export type IdealAttestationsReward = ValueOf < typeof IdealAttestationsRewardsType > ;
94-
95- /**
96- * Rewards info for actual attestations
97- */
98- export type TotalAttestationsReward = ValueOf < typeof TotalAttestationsRewardsType > ;
99-
100- export type AttestationsRewards = ValueOf < typeof AttestationsRewardsType > ;
101-
102- /**
103- * Rewards info for sync committee participation. Every reward value is in Gwei.
104- * Note: In the case that block proposer is present in `SyncCommitteeRewards`, the reward value only reflects rewards for
105- * participating in sync committee. Please refer to `BlockRewards.syncAggregate` for rewards of proposer including sync committee
106- * outputs into their block
107- */
108- export type SyncCommitteeRewards = ValueOf < typeof SyncCommitteeRewardsType > ;
109-
11010export type Endpoints = {
11111 /**
11212 * Get block rewards
@@ -116,7 +16,7 @@ export type Endpoints = {
11616 "GET" ,
11717 BlockArgs ,
11818 { params : { block_id : string } } ,
119- BlockRewards ,
19+ rewards . BlockRewards ,
12020 ExecutionOptimisticAndFinalizedMeta
12121 > ;
12222
@@ -133,7 +33,7 @@ export type Endpoints = {
13333 validatorIds ?: ValidatorId [ ] ;
13434 } ,
13535 { params : { epoch : number } ; body : string [ ] } ,
136- AttestationsRewards ,
36+ rewards . AttestationsRewards ,
13737 ExecutionOptimisticAndFinalizedMeta
13838 > ;
13939
@@ -148,7 +48,7 @@ export type Endpoints = {
14848 validatorIds ?: ValidatorId [ ] ;
14949 } ,
15050 { params : { block_id : string } ; body : string [ ] } ,
151- SyncCommitteeRewards ,
51+ rewards . SyncCommitteeRewards ,
15252 ExecutionOptimisticAndFinalizedMeta
15353 > ;
15454} ;
@@ -164,7 +64,7 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpo
16464 schema : { params : { block_id : Schema . StringRequired } } ,
16565 } ,
16666 resp : {
167- data : BlockRewardsType ,
67+ data : rewards . BlockRewardsType ,
16868 meta : ExecutionOptimisticAndFinalizedCodec ,
16969 } ,
17070 } ,
@@ -186,7 +86,7 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpo
18686 } ,
18787 } ) ,
18888 resp : {
189- data : AttestationsRewardsType ,
89+ data : rewards . AttestationsRewardsType ,
19090 meta : ExecutionOptimisticAndFinalizedCodec ,
19191 } ,
19292 } ,
@@ -208,7 +108,7 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpo
208108 } ,
209109 } ) ,
210110 resp : {
211- data : SyncCommitteeRewardsType ,
111+ data : rewards . SyncCommitteeRewardsType ,
212112 meta : ExecutionOptimisticAndFinalizedCodec ,
213113 } ,
214114 } ,
0 commit comments