-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstats.go
301 lines (262 loc) · 9.24 KB
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
package flashbots
import (
"encoding/json"
"math/big"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
"github.com/lmittmann/flashbots/internal"
"github.com/lmittmann/w3/w3types"
)
// BundleStats requests the bundles Flashbots relay stats. The given block
// number must be within 20 blocks of the current chain tip.
//
// Deprecated: Use [BundleStatsV2] instead.
func BundleStats(bundleHash common.Hash, blockNumber *big.Int) w3types.RPCCallerFactory[*BundleStatsResponse] {
return &bundleStatsFactory{bundleHash: bundleHash, blockNumber: blockNumber}
}
// BundleStatsV2 requests the bundles Flashbots relay stats. The given block
// number must be within 20 blocks of the current chain tip.
func BundleStatsV2(bundleHash common.Hash, blockNumber *big.Int) w3types.RPCCallerFactory[*BundleStatsV2Response] {
return &bundleStatsV2Factory{bundleHash: bundleHash, blockNumber: blockNumber}
}
// UserStats requests the users Flashbots relay stats. The given block number
// must be within 20 blocks of the current chain tip.
//
// Deprecated: Use [UserStatsV2] instead.
func UserStats(blockNumber *big.Int) w3types.RPCCallerFactory[*UserStatsResponse] {
return &userStatsFactory{blockNumber: blockNumber}
}
// UserStatsV2 requests the users Flashbots relay stats. The given block number
// must be within 20 blocks of the current chain tip.
func UserStatsV2(blockNumber *big.Int) w3types.RPCCallerFactory[*UserStatsV2Response] {
return &userStatsV2Factory{blockNumber: blockNumber}
}
type bundleStatsRequest struct {
BundleHash common.Hash `json:"bundleHash"`
BlockNumber *hexutil.Big `json:"blockNumber"`
}
// Deprecated: Use [BundleStatsV2Response] instead.
type BundleStatsResponse struct {
IsSimulated bool
IsSentToMiners bool
IsHighPriority bool
SimulatedAt time.Time
SubmittedAt time.Time
SentToMinersAt time.Time
}
type bundleStatsFactory struct {
// args
bundleHash common.Hash
blockNumber *big.Int
// returns
returns **BundleStatsResponse
}
func (f *bundleStatsFactory) Returns(bundleStats **BundleStatsResponse) w3types.RPCCaller {
f.returns = bundleStats
return f
}
func (f *bundleStatsFactory) CreateRequest() (rpc.BatchElem, error) {
return rpc.BatchElem{
Method: "flashbots_getBundleStats",
Args: []any{&bundleStatsRequest{
BundleHash: f.bundleHash,
BlockNumber: (*hexutil.Big)(f.blockNumber),
}},
Result: f.returns,
}, nil
}
func (f *bundleStatsFactory) HandleResponse(elem rpc.BatchElem) error {
if err := elem.Error; err != nil {
return err
}
return nil
}
type BundleStatsV2Response struct {
IsHighPriority bool
IsSimulated bool
SimulatedAt time.Time
ReceivedAt time.Time
ConsideredByBuildersAt []*struct {
Pubkey string
Timestamp time.Time
}
SealedByBuildersAt []*struct {
Pubkey string
Timestamp time.Time
}
}
type bundleStatsV2Factory struct {
// args
bundleHash common.Hash
blockNumber *big.Int
// returns
returns **BundleStatsV2Response
}
func (f *bundleStatsV2Factory) Returns(bundleStats **BundleStatsV2Response) w3types.RPCCaller {
f.returns = bundleStats
return f
}
func (f *bundleStatsV2Factory) CreateRequest() (rpc.BatchElem, error) {
return rpc.BatchElem{
Method: "flashbots_getBundleStatsV2",
Args: []any{&bundleStatsRequest{
BundleHash: f.bundleHash,
BlockNumber: (*hexutil.Big)(f.blockNumber),
}},
Result: f.returns,
}, nil
}
func (f *bundleStatsV2Factory) HandleResponse(elem rpc.BatchElem) error {
if err := elem.Error; err != nil {
return err
}
return nil
}
// Deprecated: Use [UserStatsV2Response] instead.
type UserStatsResponse struct {
IsHighPriority bool // True if the searcher has an high enough reputation to be in the high priority queue.
AllTimeMinerPayments *big.Int // Total amount paid to miners over all time.
AllTimeGasSimulated *big.Int // Total amount of gas simulated across all bundles submitted to the relay.
Last7dMinerPayments *big.Int // Total amount paid to miners over the last 7 days.
Last7dGasSimulated *big.Int // Total amount of gas simulated across all bundles submitted to the relay in the last 7 days.
Last1dMinerPayments *big.Int // Total amount paid to miners over the last day.
Last1dGasSimulated *big.Int // Total amount of gas simulated across all bundles submitted to the relay in the last day.
}
// UnmarshalJSON implements the [json.Unmarshaler].
func (u *UserStatsResponse) UnmarshalJSON(input []byte) error {
type userStatsResponse struct {
IsHighPriority *bool `json:"is_high_priority"`
AllTimeMinerPayments *internal.StrInt `json:"all_time_miner_payments"`
AllTimeGasSimulated *internal.StrInt `json:"all_time_gas_simulated"`
Last7dMinerPayments *internal.StrInt `json:"last_7d_miner_payments"`
Last7dGasSimulated *internal.StrInt `json:"last_7d_gas_simulated"`
Last1dMinerPayments *internal.StrInt `json:"last_1d_miner_payments"`
Last1dGasSimulated *internal.StrInt `json:"last_1d_gas_simulated"`
}
var dec userStatsResponse
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.IsHighPriority != nil {
u.IsHighPriority = *dec.IsHighPriority
}
if dec.AllTimeMinerPayments != nil {
u.AllTimeMinerPayments = (*big.Int)(dec.AllTimeMinerPayments)
}
if dec.AllTimeGasSimulated != nil {
u.AllTimeGasSimulated = (*big.Int)(dec.AllTimeGasSimulated)
}
if dec.Last7dMinerPayments != nil {
u.Last7dMinerPayments = (*big.Int)(dec.Last7dMinerPayments)
}
if dec.Last7dGasSimulated != nil {
u.Last7dGasSimulated = (*big.Int)(dec.Last7dGasSimulated)
}
if dec.Last1dMinerPayments != nil {
u.Last1dMinerPayments = (*big.Int)(dec.Last1dMinerPayments)
}
if dec.Last1dGasSimulated != nil {
u.Last1dGasSimulated = (*big.Int)(dec.Last1dGasSimulated)
}
return nil
}
type userStatsFactory struct {
// args
blockNumber *big.Int
// returns
returns **UserStatsResponse
}
func (f *userStatsFactory) Returns(userStats **UserStatsResponse) w3types.RPCCaller {
f.returns = userStats
return f
}
func (f *userStatsFactory) CreateRequest() (rpc.BatchElem, error) {
return rpc.BatchElem{
Method: "flashbots_getUserStats",
Args: []any{hexutil.EncodeBig(f.blockNumber)},
Result: f.returns,
}, nil
}
func (f *userStatsFactory) HandleResponse(elem rpc.BatchElem) error {
if err := elem.Error; err != nil {
return err
}
return nil
}
type userStatsV2Request struct {
BlockNumber *hexutil.Big `json:"blockNumber"`
}
type UserStatsV2Response struct {
IsHighPriority bool // True if the searcher has an high enough reputation to be in the high priority queue.
AllTimeValidatorPayments *big.Int // Total amount paid to validators over all time.
AllTimeGasSimulated *big.Int // Total amount of gas simulated across all bundles submitted to the relay.
Last7dValidatorPayments *big.Int // Total amount paid to validators over the last 7 days.
Last7dGasSimulated *big.Int // Total amount of gas simulated across all bundles submitted to the relay in the last 7 days.
Last1dValidatorPayments *big.Int // Total amount paid to validators over the last day.
Last1dGasSimulated *big.Int // Total amount of gas simulated across all bundles submitted to the relay in the last day.
}
// UnmarshalJSON implements the [json.Unmarshaler].
func (u *UserStatsV2Response) UnmarshalJSON(input []byte) error {
type userStatsV2Response struct {
IsHighPriority *bool `json:"isHighPriority"`
AllTimeValidatorPayments *internal.StrInt `json:"allTimeValidatorPayments"`
AllTimeGasSimulated *internal.StrInt `json:"allTimeGasSimulated"`
Last7dValidatorPayments *internal.StrInt `json:"last7dValidatorPayments"`
Last7dGasSimulated *internal.StrInt `json:"last7dGasSimulated"`
Last1dValidatorPayments *internal.StrInt `json:"last1dValidatorPayments"`
Last1dGasSimulated *internal.StrInt `json:"last1dGasSimulated"`
}
var dec userStatsV2Response
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.IsHighPriority != nil {
u.IsHighPriority = *dec.IsHighPriority
}
if dec.AllTimeValidatorPayments != nil {
u.AllTimeValidatorPayments = (*big.Int)(dec.AllTimeValidatorPayments)
}
if dec.AllTimeGasSimulated != nil {
u.AllTimeGasSimulated = (*big.Int)(dec.AllTimeGasSimulated)
}
if dec.Last7dValidatorPayments != nil {
u.Last7dValidatorPayments = (*big.Int)(dec.Last7dValidatorPayments)
}
if dec.Last7dGasSimulated != nil {
u.Last7dGasSimulated = (*big.Int)(dec.Last7dGasSimulated)
}
if dec.Last1dValidatorPayments != nil {
u.Last1dValidatorPayments = (*big.Int)(dec.Last1dValidatorPayments)
}
if dec.Last1dGasSimulated != nil {
u.Last1dGasSimulated = (*big.Int)(dec.Last1dGasSimulated)
}
return nil
}
type userStatsV2Factory struct {
// args
blockNumber *big.Int
// returns
returns **UserStatsV2Response
}
func (f *userStatsV2Factory) Returns(userStats **UserStatsV2Response) w3types.RPCCaller {
f.returns = userStats
return f
}
func (f *userStatsV2Factory) CreateRequest() (rpc.BatchElem, error) {
return rpc.BatchElem{
Method: "flashbots_getUserStatsV2",
Args: []any{&userStatsV2Request{
BlockNumber: (*hexutil.Big)(f.blockNumber),
}},
Result: f.returns,
}, nil
}
func (f *userStatsV2Factory) HandleResponse(elem rpc.BatchElem) error {
if err := elem.Error; err != nil {
return err
}
return nil
}