|
| 1 | +package flashbotsrpc |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "encoding/json" |
| 6 | + "math/big" |
| 7 | + "unsafe" |
| 8 | +) |
| 9 | + |
| 10 | +// Syncing - object with syncing data info |
| 11 | +type Syncing struct { |
| 12 | + IsSyncing bool |
| 13 | + StartingBlock int |
| 14 | + CurrentBlock int |
| 15 | + HighestBlock int |
| 16 | +} |
| 17 | + |
| 18 | +// UnmarshalJSON implements the json.Unmarshaler interface. |
| 19 | +func (s *Syncing) UnmarshalJSON(data []byte) error { |
| 20 | + proxy := new(proxySyncing) |
| 21 | + if err := json.Unmarshal(data, proxy); err != nil { |
| 22 | + return err |
| 23 | + } |
| 24 | + |
| 25 | + proxy.IsSyncing = true |
| 26 | + *s = *(*Syncing)(unsafe.Pointer(proxy)) |
| 27 | + |
| 28 | + return nil |
| 29 | +} |
| 30 | + |
| 31 | +// T - input transaction object |
| 32 | +type T struct { |
| 33 | + From string |
| 34 | + To string |
| 35 | + Gas int |
| 36 | + GasPrice *big.Int |
| 37 | + Value *big.Int |
| 38 | + Data string |
| 39 | + Nonce int |
| 40 | +} |
| 41 | + |
| 42 | +// MarshalJSON implements the json.Unmarshaler interface. |
| 43 | +func (t T) MarshalJSON() ([]byte, error) { |
| 44 | + params := map[string]interface{}{ |
| 45 | + "from": t.From, |
| 46 | + } |
| 47 | + if t.To != "" { |
| 48 | + params["to"] = t.To |
| 49 | + } |
| 50 | + if t.Gas > 0 { |
| 51 | + params["gas"] = IntToHex(t.Gas) |
| 52 | + } |
| 53 | + if t.GasPrice != nil { |
| 54 | + params["gasPrice"] = BigToHex(*t.GasPrice) |
| 55 | + } |
| 56 | + if t.Value != nil { |
| 57 | + params["value"] = BigToHex(*t.Value) |
| 58 | + } |
| 59 | + if t.Data != "" { |
| 60 | + params["data"] = t.Data |
| 61 | + } |
| 62 | + if t.Nonce > 0 { |
| 63 | + params["nonce"] = IntToHex(t.Nonce) |
| 64 | + } |
| 65 | + |
| 66 | + return json.Marshal(params) |
| 67 | +} |
| 68 | + |
| 69 | +// Transaction - transaction object |
| 70 | +type Transaction struct { |
| 71 | + Hash string |
| 72 | + Nonce int |
| 73 | + BlockHash string |
| 74 | + BlockNumber *int |
| 75 | + TransactionIndex *int |
| 76 | + From string |
| 77 | + To string |
| 78 | + Value big.Int |
| 79 | + Gas int |
| 80 | + GasPrice big.Int |
| 81 | + Input string |
| 82 | +} |
| 83 | + |
| 84 | +// UnmarshalJSON implements the json.Unmarshaler interface. |
| 85 | +func (t *Transaction) UnmarshalJSON(data []byte) error { |
| 86 | + proxy := new(proxyTransaction) |
| 87 | + if err := json.Unmarshal(data, proxy); err != nil { |
| 88 | + return err |
| 89 | + } |
| 90 | + |
| 91 | + *t = *(*Transaction)(unsafe.Pointer(proxy)) |
| 92 | + |
| 93 | + return nil |
| 94 | +} |
| 95 | + |
| 96 | +// Log - log object |
| 97 | +type Log struct { |
| 98 | + Removed bool |
| 99 | + LogIndex int |
| 100 | + TransactionIndex int |
| 101 | + TransactionHash string |
| 102 | + BlockNumber int |
| 103 | + BlockHash string |
| 104 | + Address string |
| 105 | + Data string |
| 106 | + Topics []string |
| 107 | +} |
| 108 | + |
| 109 | +// UnmarshalJSON implements the json.Unmarshaler interface. |
| 110 | +func (log *Log) UnmarshalJSON(data []byte) error { |
| 111 | + proxy := new(proxyLog) |
| 112 | + if err := json.Unmarshal(data, proxy); err != nil { |
| 113 | + return err |
| 114 | + } |
| 115 | + |
| 116 | + *log = *(*Log)(unsafe.Pointer(proxy)) |
| 117 | + |
| 118 | + return nil |
| 119 | +} |
| 120 | + |
| 121 | +// FilterParams - Filter parameters object |
| 122 | +type FilterParams struct { |
| 123 | + FromBlock string `json:"fromBlock,omitempty"` |
| 124 | + ToBlock string `json:"toBlock,omitempty"` |
| 125 | + Address []string `json:"address,omitempty"` |
| 126 | + Topics [][]string `json:"topics,omitempty"` |
| 127 | +} |
| 128 | + |
| 129 | +// TransactionReceipt - transaction receipt object |
| 130 | +type TransactionReceipt struct { |
| 131 | + TransactionHash string |
| 132 | + TransactionIndex int |
| 133 | + BlockHash string |
| 134 | + BlockNumber int |
| 135 | + CumulativeGasUsed int |
| 136 | + GasUsed int |
| 137 | + ContractAddress string |
| 138 | + Logs []Log |
| 139 | + LogsBloom string |
| 140 | + Root string |
| 141 | + Status string |
| 142 | +} |
| 143 | + |
| 144 | +// UnmarshalJSON implements the json.Unmarshaler interface. |
| 145 | +func (t *TransactionReceipt) UnmarshalJSON(data []byte) error { |
| 146 | + proxy := new(proxyTransactionReceipt) |
| 147 | + if err := json.Unmarshal(data, proxy); err != nil { |
| 148 | + return err |
| 149 | + } |
| 150 | + |
| 151 | + *t = *(*TransactionReceipt)(unsafe.Pointer(proxy)) |
| 152 | + |
| 153 | + return nil |
| 154 | +} |
| 155 | + |
| 156 | +// Block - block object |
| 157 | +type Block struct { |
| 158 | + Number int |
| 159 | + Hash string |
| 160 | + ParentHash string |
| 161 | + Nonce string |
| 162 | + Sha3Uncles string |
| 163 | + LogsBloom string |
| 164 | + TransactionsRoot string |
| 165 | + StateRoot string |
| 166 | + Miner string |
| 167 | + Difficulty big.Int |
| 168 | + TotalDifficulty big.Int |
| 169 | + ExtraData string |
| 170 | + Size int |
| 171 | + GasLimit int |
| 172 | + GasUsed int |
| 173 | + Timestamp int |
| 174 | + Uncles []string |
| 175 | + Transactions []Transaction |
| 176 | +} |
| 177 | + |
| 178 | +type proxySyncing struct { |
| 179 | + IsSyncing bool `json:"-"` |
| 180 | + StartingBlock hexInt `json:"startingBlock"` |
| 181 | + CurrentBlock hexInt `json:"currentBlock"` |
| 182 | + HighestBlock hexInt `json:"highestBlock"` |
| 183 | +} |
| 184 | + |
| 185 | +type proxyTransaction struct { |
| 186 | + Hash string `json:"hash"` |
| 187 | + Nonce hexInt `json:"nonce"` |
| 188 | + BlockHash string `json:"blockHash"` |
| 189 | + BlockNumber *hexInt `json:"blockNumber"` |
| 190 | + TransactionIndex *hexInt `json:"transactionIndex"` |
| 191 | + From string `json:"from"` |
| 192 | + To string `json:"to"` |
| 193 | + Value hexBig `json:"value"` |
| 194 | + Gas hexInt `json:"gas"` |
| 195 | + GasPrice hexBig `json:"gasPrice"` |
| 196 | + Input string `json:"input"` |
| 197 | +} |
| 198 | + |
| 199 | +type proxyLog struct { |
| 200 | + Removed bool `json:"removed"` |
| 201 | + LogIndex hexInt `json:"logIndex"` |
| 202 | + TransactionIndex hexInt `json:"transactionIndex"` |
| 203 | + TransactionHash string `json:"transactionHash"` |
| 204 | + BlockNumber hexInt `json:"blockNumber"` |
| 205 | + BlockHash string `json:"blockHash"` |
| 206 | + Address string `json:"address"` |
| 207 | + Data string `json:"data"` |
| 208 | + Topics []string `json:"topics"` |
| 209 | +} |
| 210 | + |
| 211 | +type proxyTransactionReceipt struct { |
| 212 | + TransactionHash string `json:"transactionHash"` |
| 213 | + TransactionIndex hexInt `json:"transactionIndex"` |
| 214 | + BlockHash string `json:"blockHash"` |
| 215 | + BlockNumber hexInt `json:"blockNumber"` |
| 216 | + CumulativeGasUsed hexInt `json:"cumulativeGasUsed"` |
| 217 | + GasUsed hexInt `json:"gasUsed"` |
| 218 | + ContractAddress string `json:"contractAddress,omitempty"` |
| 219 | + Logs []Log `json:"logs"` |
| 220 | + LogsBloom string `json:"logsBloom"` |
| 221 | + Root string `json:"root"` |
| 222 | + Status string `json:"status,omitempty"` |
| 223 | +} |
| 224 | + |
| 225 | +type hexInt int |
| 226 | + |
| 227 | +func (i *hexInt) UnmarshalJSON(data []byte) error { |
| 228 | + result, err := ParseInt(string(bytes.Trim(data, `"`))) |
| 229 | + *i = hexInt(result) |
| 230 | + |
| 231 | + return err |
| 232 | +} |
| 233 | + |
| 234 | +type hexBig big.Int |
| 235 | + |
| 236 | +func (i *hexBig) UnmarshalJSON(data []byte) error { |
| 237 | + result, err := ParseBigInt(string(bytes.Trim(data, `"`))) |
| 238 | + *i = hexBig(result) |
| 239 | + |
| 240 | + return err |
| 241 | +} |
| 242 | + |
| 243 | +type proxyBlock interface { |
| 244 | + toBlock() Block |
| 245 | +} |
| 246 | + |
| 247 | +type proxyBlockWithTransactions struct { |
| 248 | + Number hexInt `json:"number"` |
| 249 | + Hash string `json:"hash"` |
| 250 | + ParentHash string `json:"parentHash"` |
| 251 | + Nonce string `json:"nonce"` |
| 252 | + Sha3Uncles string `json:"sha3Uncles"` |
| 253 | + LogsBloom string `json:"logsBloom"` |
| 254 | + TransactionsRoot string `json:"transactionsRoot"` |
| 255 | + StateRoot string `json:"stateRoot"` |
| 256 | + Miner string `json:"miner"` |
| 257 | + Difficulty hexBig `json:"difficulty"` |
| 258 | + TotalDifficulty hexBig `json:"totalDifficulty"` |
| 259 | + ExtraData string `json:"extraData"` |
| 260 | + Size hexInt `json:"size"` |
| 261 | + GasLimit hexInt `json:"gasLimit"` |
| 262 | + GasUsed hexInt `json:"gasUsed"` |
| 263 | + Timestamp hexInt `json:"timestamp"` |
| 264 | + Uncles []string `json:"uncles"` |
| 265 | + Transactions []proxyTransaction `json:"transactions"` |
| 266 | +} |
| 267 | + |
| 268 | +func (proxy *proxyBlockWithTransactions) toBlock() Block { |
| 269 | + return *(*Block)(unsafe.Pointer(proxy)) |
| 270 | +} |
| 271 | + |
| 272 | +type proxyBlockWithoutTransactions struct { |
| 273 | + Number hexInt `json:"number"` |
| 274 | + Hash string `json:"hash"` |
| 275 | + ParentHash string `json:"parentHash"` |
| 276 | + Nonce string `json:"nonce"` |
| 277 | + Sha3Uncles string `json:"sha3Uncles"` |
| 278 | + LogsBloom string `json:"logsBloom"` |
| 279 | + TransactionsRoot string `json:"transactionsRoot"` |
| 280 | + StateRoot string `json:"stateRoot"` |
| 281 | + Miner string `json:"miner"` |
| 282 | + Difficulty hexBig `json:"difficulty"` |
| 283 | + TotalDifficulty hexBig `json:"totalDifficulty"` |
| 284 | + ExtraData string `json:"extraData"` |
| 285 | + Size hexInt `json:"size"` |
| 286 | + GasLimit hexInt `json:"gasLimit"` |
| 287 | + GasUsed hexInt `json:"gasUsed"` |
| 288 | + Timestamp hexInt `json:"timestamp"` |
| 289 | + Uncles []string `json:"uncles"` |
| 290 | + Transactions []string `json:"transactions"` |
| 291 | +} |
| 292 | + |
| 293 | +func (proxy *proxyBlockWithoutTransactions) toBlock() Block { |
| 294 | + block := Block{ |
| 295 | + Number: int(proxy.Number), |
| 296 | + Hash: proxy.Hash, |
| 297 | + ParentHash: proxy.ParentHash, |
| 298 | + Nonce: proxy.Nonce, |
| 299 | + Sha3Uncles: proxy.Sha3Uncles, |
| 300 | + LogsBloom: proxy.LogsBloom, |
| 301 | + TransactionsRoot: proxy.TransactionsRoot, |
| 302 | + StateRoot: proxy.StateRoot, |
| 303 | + Miner: proxy.Miner, |
| 304 | + Difficulty: big.Int(proxy.Difficulty), |
| 305 | + TotalDifficulty: big.Int(proxy.TotalDifficulty), |
| 306 | + ExtraData: proxy.ExtraData, |
| 307 | + Size: int(proxy.Size), |
| 308 | + GasLimit: int(proxy.GasLimit), |
| 309 | + GasUsed: int(proxy.GasUsed), |
| 310 | + Timestamp: int(proxy.Timestamp), |
| 311 | + Uncles: proxy.Uncles, |
| 312 | + } |
| 313 | + |
| 314 | + block.Transactions = make([]Transaction, len(proxy.Transactions)) |
| 315 | + for i := range proxy.Transactions { |
| 316 | + block.Transactions[i] = Transaction{ |
| 317 | + Hash: proxy.Transactions[i], |
| 318 | + } |
| 319 | + } |
| 320 | + |
| 321 | + return block |
| 322 | +} |
| 323 | + |
| 324 | +type FlashbotsUserStats struct { |
| 325 | + IsHighPriority bool `json:"is_high_priority"` |
| 326 | + AllTimeMinerPayments string `json:"all_time_miner_payments"` |
| 327 | + AllTimeGasSimulated string `json:"all_time_gas_simulated"` |
| 328 | + Last7dMinerPayments string `json:"last_7d_miner_payments"` |
| 329 | + Last7dGasSimulated string `json:"last_7d_gas_simulated"` |
| 330 | + Last1dMinerPayments string `json:"last_1d_miner_payments"` |
| 331 | + Last1dGasSimulated string `json:"last_1d_gas_simulated"` |
| 332 | +} |
| 333 | + |
| 334 | +type FlashbotsCallBundleParam struct { |
| 335 | + Txs []string `json:"txs"` // Array[String], A list of signed transactions to execute in an atomic bundle |
| 336 | + BlockNumber string `json:"blockNumber"` // String, a hex encoded block number for which this bundle is valid on |
| 337 | + StateBlockNumber string `json:"stateBlockNumber"` // String, either a hex encoded number or a block tag for which state to base this simulation on. Can use "latest" |
| 338 | + Timestamp int64 `json:"timestamp,omitempty"` // Number, the timestamp to use for this bundle simulation, in seconds since the unix epoch |
| 339 | + Timeout int64 `json:"timeout,omitempty"` |
| 340 | + GasLimit uint64 `json:"gasLimit,omitempty"` |
| 341 | + Difficulty uint64 `json:"difficulty,omitempty"` |
| 342 | + BaseFee uint64 `json:"baseFee,omitempty"` |
| 343 | +} |
| 344 | + |
| 345 | +type FlashbotsCallBundleResult struct { |
| 346 | + CoinbaseDiff string `json:"coinbaseDiff"` // "2717471092204423", |
| 347 | + EthSentToCoinbase string `json:"ethSentToCoinbase"` // "0", |
| 348 | + FromAddress string `json:"fromAddress"` // "0x37ff310ab11d1928BB70F37bC5E3cf62Df09a01c", |
| 349 | + GasFees string `json:"gasFees"` // "2717471092204423", |
| 350 | + GasPrice string `json:"gasPrice"` // "43000001459", |
| 351 | + GasUsed int64 `json:"gasUsed"` // 63197, |
| 352 | + ToAddress string `json:"toAddress"` // "0xdAC17F958D2ee523a2206206994597C13D831ec7", |
| 353 | + TxHash string `json:"txHash"` // "0xe2df005210bdc204a34ff03211606e5d8036740c686e9fe4e266ae91cf4d12df", |
| 354 | + Value string `json:"value"` // "0x" |
| 355 | +} |
| 356 | + |
| 357 | +type FlashbotsCallBundleResponse struct { |
| 358 | + BundleGasPrice string `json:"bundleGasPrice"` // "43000001459", |
| 359 | + BundleHash string `json:"bundleHash"` // "0x2ca9c4d2ba00d8144d8e396a4989374443cb20fb490d800f4f883ad4e1b32158", |
| 360 | + CoinbaseDiff string `json:"coinbaseDiff"` // "2717471092204423", |
| 361 | + EthSentToCoinbase string `json:"ethSentToCoinbase"` // "0", |
| 362 | + GasFees string `json:"gasFees"` // "2717471092204423", |
| 363 | + Results []FlashbotsCallBundleResult `json:"results"` // [], |
| 364 | + StateBlockNumber int64 `json:"stateBlockNumber"` // 12960319, |
| 365 | + TotalGasUsed int64 `json:"totalGasUsed"` // 63197 |
| 366 | +} |
0 commit comments