forked from metachris/flashbotsrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
458 lines (406 loc) · 21.8 KB
/
types.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
package flashxroute
import (
"bytes"
"encoding/json"
"math/big"
"unsafe"
"github.com/pkg/errors"
)
// ErrRelayErrorResponse means it's a standard Flashbots relay error response - probably a user error rather than JSON or network error
var ErrRelayErrorResponse = errors.New("relay error response")
// Syncing - object with syncing data info
type Syncing struct {
IsSyncing bool
StartingBlock int
CurrentBlock int
HighestBlock int
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (s *Syncing) UnmarshalJSON(data []byte) error {
proxy := new(proxySyncing)
if err := json.Unmarshal(data, proxy); err != nil {
return err
}
proxy.IsSyncing = true
*s = *(*Syncing)(unsafe.Pointer(proxy))
return nil
}
// T - input transaction object
type T struct {
From string
To string
Gas int
GasPrice *big.Int
Value *big.Int
Data string
Nonce int
}
// MarshalJSON implements the json.Unmarshaler interface.
func (t T) MarshalJSON() ([]byte, error) {
params := map[string]interface{}{
"from": t.From,
}
if t.To != "" {
params["to"] = t.To
}
if t.Gas > 0 {
params["gas"] = IntToHex(t.Gas)
}
if t.GasPrice != nil {
params["gasPrice"] = BigToHex(*t.GasPrice)
}
if t.Value != nil {
params["value"] = BigToHex(*t.Value)
}
if t.Data != "" {
params["data"] = t.Data
}
if t.Nonce > 0 {
params["nonce"] = IntToHex(t.Nonce)
}
return json.Marshal(params)
}
// Transaction - transaction object
type Transaction struct {
Hash string
Nonce int
BlockHash string
BlockNumber *int
TransactionIndex *int
From string
To string
Value big.Int
Gas int
GasPrice big.Int
Input string
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (t *Transaction) UnmarshalJSON(data []byte) error {
proxy := new(proxyTransaction)
if err := json.Unmarshal(data, proxy); err != nil {
return err
}
*t = *(*Transaction)(unsafe.Pointer(proxy))
return nil
}
// Log - log object
type Log struct {
Removed bool
LogIndex int
TransactionIndex int
TransactionHash string
BlockNumber int
BlockHash string
Address string
Data string
Topics []string
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (log *Log) UnmarshalJSON(data []byte) error {
proxy := new(proxyLog)
if err := json.Unmarshal(data, proxy); err != nil {
return err
}
*log = *(*Log)(unsafe.Pointer(proxy))
return nil
}
// FilterParams - Filter parameters object
type FilterParams struct {
FromBlock string `json:"fromBlock,omitempty"`
ToBlock string `json:"toBlock,omitempty"`
Address []string `json:"address,omitempty"`
Topics [][]string `json:"topics,omitempty"`
}
// TransactionReceipt - transaction receipt object
type TransactionReceipt struct {
TransactionHash string
TransactionIndex int
BlockHash string
BlockNumber int
CumulativeGasUsed int
GasUsed int
ContractAddress string
Logs []Log
LogsBloom string
Root string
Status string
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (t *TransactionReceipt) UnmarshalJSON(data []byte) error {
proxy := new(proxyTransactionReceipt)
if err := json.Unmarshal(data, proxy); err != nil {
return err
}
*t = *(*TransactionReceipt)(unsafe.Pointer(proxy))
return nil
}
// Block - block object
type Block struct {
Number int
Hash string
ParentHash string
Nonce string
Sha3Uncles string
LogsBloom string
TransactionsRoot string
StateRoot string
Miner string
Difficulty big.Int
TotalDifficulty big.Int
ExtraData string
Size int
GasLimit int
GasUsed int
Timestamp int
Uncles []string
Transactions []Transaction
}
type proxySyncing struct {
IsSyncing bool `json:"-"`
StartingBlock hexInt `json:"startingBlock"`
CurrentBlock hexInt `json:"currentBlock"`
HighestBlock hexInt `json:"highestBlock"`
}
type proxyTransaction struct {
Hash string `json:"hash"`
Nonce hexInt `json:"nonce"`
BlockHash string `json:"blockHash"`
BlockNumber *hexInt `json:"blockNumber"`
TransactionIndex *hexInt `json:"transactionIndex"`
From string `json:"from"`
To string `json:"to"`
Value hexBig `json:"value"`
Gas hexInt `json:"gas"`
GasPrice hexBig `json:"gasPrice"`
Input string `json:"input"`
}
type proxyLog struct {
Removed bool `json:"removed"`
LogIndex hexInt `json:"logIndex"`
TransactionIndex hexInt `json:"transactionIndex"`
TransactionHash string `json:"transactionHash"`
BlockNumber hexInt `json:"blockNumber"`
BlockHash string `json:"blockHash"`
Address string `json:"address"`
Data string `json:"data"`
Topics []string `json:"topics"`
}
type proxyTransactionReceipt struct {
TransactionHash string `json:"transactionHash"`
TransactionIndex hexInt `json:"transactionIndex"`
BlockHash string `json:"blockHash"`
BlockNumber hexInt `json:"blockNumber"`
CumulativeGasUsed hexInt `json:"cumulativeGasUsed"`
GasUsed hexInt `json:"gasUsed"`
ContractAddress string `json:"contractAddress,omitempty"`
Logs []Log `json:"logs"`
LogsBloom string `json:"logsBloom"`
Root string `json:"root"`
Status string `json:"status,omitempty"`
}
type hexInt int
func (i *hexInt) UnmarshalJSON(data []byte) error {
result, err := ParseInt(string(bytes.Trim(data, `"`)))
*i = hexInt(result)
return err
}
type hexBig big.Int
func (i *hexBig) UnmarshalJSON(data []byte) error {
result, err := ParseBigInt(string(bytes.Trim(data, `"`)))
*i = hexBig(result)
return err
}
type proxyBlock interface {
toBlock() Block
}
type proxyBlockWithTransactions struct {
Number hexInt `json:"number"`
Hash string `json:"hash"`
ParentHash string `json:"parentHash"`
Nonce string `json:"nonce"`
Sha3Uncles string `json:"sha3Uncles"`
LogsBloom string `json:"logsBloom"`
TransactionsRoot string `json:"transactionsRoot"`
StateRoot string `json:"stateRoot"`
Miner string `json:"miner"`
Difficulty hexBig `json:"difficulty"`
TotalDifficulty hexBig `json:"totalDifficulty"`
ExtraData string `json:"extraData"`
Size hexInt `json:"size"`
GasLimit hexInt `json:"gasLimit"`
GasUsed hexInt `json:"gasUsed"`
Timestamp hexInt `json:"timestamp"`
Uncles []string `json:"uncles"`
Transactions []proxyTransaction `json:"transactions"`
}
func (proxy *proxyBlockWithTransactions) toBlock() Block {
return *(*Block)(unsafe.Pointer(proxy))
}
type proxyBlockWithoutTransactions struct {
Number hexInt `json:"number"`
Hash string `json:"hash"`
ParentHash string `json:"parentHash"`
Nonce string `json:"nonce"`
Sha3Uncles string `json:"sha3Uncles"`
LogsBloom string `json:"logsBloom"`
TransactionsRoot string `json:"transactionsRoot"`
StateRoot string `json:"stateRoot"`
Miner string `json:"miner"`
Difficulty hexBig `json:"difficulty"`
TotalDifficulty hexBig `json:"totalDifficulty"`
ExtraData string `json:"extraData"`
Size hexInt `json:"size"`
GasLimit hexInt `json:"gasLimit"`
GasUsed hexInt `json:"gasUsed"`
Timestamp hexInt `json:"timestamp"`
Uncles []string `json:"uncles"`
Transactions []string `json:"transactions"`
}
func (proxy *proxyBlockWithoutTransactions) toBlock() Block {
block := Block{
Number: int(proxy.Number),
Hash: proxy.Hash,
ParentHash: proxy.ParentHash,
Nonce: proxy.Nonce,
Sha3Uncles: proxy.Sha3Uncles,
LogsBloom: proxy.LogsBloom,
TransactionsRoot: proxy.TransactionsRoot,
StateRoot: proxy.StateRoot,
Miner: proxy.Miner,
Difficulty: big.Int(proxy.Difficulty),
TotalDifficulty: big.Int(proxy.TotalDifficulty),
ExtraData: proxy.ExtraData,
Size: int(proxy.Size),
GasLimit: int(proxy.GasLimit),
GasUsed: int(proxy.GasUsed),
Timestamp: int(proxy.Timestamp),
Uncles: proxy.Uncles,
}
block.Transactions = make([]Transaction, len(proxy.Transactions))
for i := range proxy.Transactions {
block.Transactions[i] = Transaction{
Hash: proxy.Transactions[i],
}
}
return block
}
type RelayErrorResponse struct {
Error string `json:"error"`
}
type BloxrouteSimulateBundleRequest struct {
Transaction []string `json:"transaction"` // A list of raw transaction bytes without a 0x prefix.
BlockNumber string `json:"block_number"` // Block number of a future block to include this bundle in, in hex value.
StateBlockNumber string `json:"state_block_number,omitempty"` /* [Optional] Block number used as the base state to run a simulation on.
Valid inputs include hex value of block number, or tags like “latest” and “pending”.
Default value is “latest”. */
Timestamp int64 `json:"timestamp,omitempty"` // [Optional] Simulation timestamp, an integer in unix epoch format. Default value is None.
}
type BloxrouteBrmSimulateBundleRequest struct {
TransactionHash string `json:"transaction_hash"` // Trigger private transaction hash.
Transaction []string `json:"transaction"` // A list of raw transaction bytes without a 0x prefix.
BlockNumber string `json:"block_number"` // Block number of a future block to include this bundle in, in hex value.
StateBlockNumber string `json:"state_block_number,omitempty"` /* [Optional] Block number used as the base state to run a simulation on.
Valid inputs include hex value of block number, or tags like “latest” and “pending”.
Default value is “latest”. */
Timestamp uint64 `json:"timestamp,omitempty"` // [Optional] Simulation timestamp, an integer in unix epoch format. Default value is None.
}
type BloxrouteSimulateBundleResult struct {
GasUsed int64 `json:"gasUsed"` // 63197,
TxHash string `json:"txHash"` // "0xe2df005210bdc204a34ff03211606e5d8036740c686e9fe4e266ae91cf4d12df",
Value string `json:"value"` // "0x"
Error string `json:"error"`
}
type BloxrouteSimulateBundleResponse struct {
BundleGasPrice string `json:"bundleGasPrice"` // "43000001459",
BundleHash string `json:"bundleHash"` // "0x2ca9c4d2ba00d8144d8e396a4989374443cb20fb490d800f4f883ad4e1b32158",
CoinbaseDiff string `json:"coinbaseDiff"` // "2717471092204423",
EthSentToCoinbase string `json:"ethSentToCoinbase"` // "0",
GasFees string `json:"gasFees"` // "2717471092204423",
Results []BloxrouteSimulateBundleResult `json:"results"` // [],
StateBlockNumber int64 `json:"stateBlockNumber"` // 12960319,
TotalGasUsed int64 `json:"totalGasUsed"` // 63197
}
type BloxrouteBrmSimulateBundleResponse struct {
BloxrouteDiff string `json:"bloxrouteDiff"` // "10000"
BundleGasPrice string `json:"bundleGasPrice"` // "43000001459",
BundleHash string `json:"bundleHash"` // "0x2ca9c4d2ba00d8144d8e396a4989374443cb20fb490d800f4f883ad4e1b32158",
CoinbaseDiff string `json:"coinbaseDiff"` // "2717471092204423",
EthSentToCoinbase string `json:"ethSentToCoinbase"` // "0",
GasFees string `json:"gasFees"` // "2717471092204423",
MinerDiff string `json:"minerDiff"` // "100000"
Results []BloxrouteSimulateBundleResult `json:"results"` // [],
SenderDiff string `json:"senderDiff"` // "50000"
StateBlockNumber int64 `json:"stateBlockNumber"` // 12960319,
TotalGasUsed int64 `json:"totalGasUsed"` // 63197
Status string `json:"status"` // "good"
}
// SubmitBundle
type BloxrouteSubmitBundleRequest struct {
Transaction []string `json:"transaction"` // A list of raw transaction bytes without a 0x prefix.
BlockNumber string `json:"block_number"` /* Block number of a future block to include this bundle in, in hex value.
For traders who would like more than one block to be targeted, please send multiple requests targeting each specific block. */
MinTimestamp *uint64 `json:"min_timestamp,omitempty"` // [Optional] The minimum timestamp that the bundle is valid on, an integer in unix epoch format. Default value is None.
MaxTimestamp *uint64 `json:"max_timestamp,omitempty"` // [Optional] The maximum timestamp that the bundle is valid on, an integer in unix epoch format. Default value is None.
RevertingHashes *[]string `json:"reverting_hashes,omitempty"` /* [Optional] A list of transaction hashes within the bundle that are allowed to revert.
Default is empty list: the whole bundle would be excluded if any transaction reverts. */
Uuid string `json:"uuid,omitempty"` /* [Optional] A unique identifier of the bundle. This field can be used for bundle replacement and bundle cancellation.
Some builders like bloxroute and builder0x69 support this field. After receiving a new UUID bundle,
the builder would replace the previous bundle that has the same UUID. When the list of transactions is empty in new UUID bundle,
the previous bundle associated with the same UUID would be effectively canceled.
The response is empty/null instead of bundle hash when UUID is provided in the request. */
Frontrunning bool `json:"frontrunning,omitempty"` /* [Optional, default: True] A boolean flag indicating if the MEV bundle executes frontrunning strategy (e.g. generalized frontrunning,
sandwiching). Some block builders and validators may not want to accept frontrunning bundles, which may experience a lower hash power. */
EffectiveGasPrice *string `json:"effective_gas_price,omitempty"` // [Optional, default: 0] An integer representing current bundle's effective gas price in wei.
CoinbaseProfit *string `json:"coinbase_profit,omitempty"` // [Optional, default: 0] An integer representing current bundle's coinbase profit in wei.
MevBuilders *[]string `json:"mev_builders,omitempty"` /* [Optional, default: bloxroute builder and flashbots builder] A dictionary of MEV builders that should receive the bundle.
For each MEV builder, a signature is required. For flashbots builder, please provide the signature used in X-Flashbots-Signature header.
For other builders, please provide empty string as signature.
Possible MEV builders are:
bloxroute: bloXroute internal builder
flashbots: flashbots builder
builder0x69: builder0x69
beaverbuild: beaverbuild.org
all: all builders
Traders can refer to List of External Builders page for a full list. */
}
// BackRunMeSubmitBundle
type BloxrouteBrmSubmitBundleRequest struct {
TransactionHash string `json:"transaction_hash"` // Trigger transaction hash
Transaction []string `json:"transaction"` // A list of raw transaction bytes without a 0x prefix.
BlockNumber string `json:"block_number"` /* Block number of a future block to include this bundle in, in hex value.
For traders who would like more than one block to be targeted, please send multiple requests targeting each specific block. */
MinTimestamp *uint64 `json:"min_timestamp,omitempty"` // [Optional] The minimum timestamp that the bundle is valid on, an integer in unix epoch format. Default value is None.
MaxTimestamp *uint64 `json:"max_timestamp,omitempty"` // [Optional] The maximum timestamp that the bundle is valid on, an integer in unix epoch format. Default value is None.
}
type BloxrouteSubmitBundleResponse struct {
BundleHash string `json:"bundleHash"`
}
// SendTransaction
type BloxrouteSendTransactionRequest struct {
Transaction string `json:"transaction"` // [Mandatory] Raw transactions bytes without 0x prefix.
NonceMonitoring bool `json:"nonce_monitoring,omitempty"` /* [Optional, default: False] A boolean flag indicating if Tx Nonce Monitoring should be enabled for the transaction.
This parameter only effects Cloud-API requests.
*Currently only available for users testing the Beta version, but will soon be available to all. */
BlockchainNetwork string `json:""blockchain_network,omitempty` /* [Optional, default: Mainnet] Blockchain network name. Use with Cloud-API when working with BSC.
Available options are: Mainnet for ETH Mainnet, BSC-Mainnet for BSC Mainnet, and Polygon-Mainnet for Polygon Mainnet. */
ValidatorsOnly bool `json:"validators_only,omitempty"` // [Optional, default: False] Support for semi private transactions in all networks. See section Semi-Private Transaction for more info.
}
// SendPrivateTransaction
type BloxrouteSendPrivateTransactionRequest struct {
Transaction string `json:"transaction"` // [Mandatory] Raw transactions bytes without 0x prefix.
Timeout *uint64 `json:"timeout,omitempty"` /* [Optional] An integer value that represents the time, in seconds, needed to wait for a Private Transaction to be included in a block.
If omitted, it defaults to 0. If timeout is not 0 and the transaction is not mined after the timeout value,
it will be sent publicly. If the timeout is 0, no public transaction will be sent. */
Frontrunning bool `json:"frontrunning,omitempty"` /* [Optional, default: True] A boolean flag indicating if the MEV bundle executes frontrunning strategy (e.g. generalized frontrunning,
sandwiching). Some block builders and validators may not want to accept frontrunning bundles, which may experience a lower hash power. */
MevBuilders *[]string `json:"mev_builders,omitempty"` /* [Optional, default: bloxroute builder and flashbots builder] A dictionary of MEV builders that should receive the bundle.
For each MEV builder, a signature is required. For flashbots builder, please provide the signature used in X-Flashbots-Signature header.
For other builders, please provide empty string as signature.
Possible MEV builders are:
bloxroute: bloXroute internal builder
flashbots: flashbots builder
builder0x69: builder0x69
beaverbuild: beaverbuild.org
all: all builders
Traders can refer to List of External Builders page for a full list. */
}