-
Notifications
You must be signed in to change notification settings - Fork 14
/
types.go
206 lines (181 loc) · 5.68 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
package mevshare
import (
"encoding/json"
"errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
)
var (
ErrInvalidHintIntent = errors.New("invalid hint intent")
ErrNilBundleMetadata = errors.New("bundle metadata is nil")
)
// HintIntent is a set of hint intents
// its marshalled as an array of strings
type HintIntent uint8
const (
HintContractAddress HintIntent = 1 << iota
HintFunctionSelector
HintLogs
HintCallData
HintHash
HintSpecialLogs
HintTxHash
HintNone = 0
)
func (b *HintIntent) SetHint(flag HintIntent) {
*b = *b | flag
}
func (b *HintIntent) HasHint(flag HintIntent) bool {
return *b&flag != 0
}
func (b HintIntent) MarshalJSON() ([]byte, error) {
var arr []string
if b.HasHint(HintContractAddress) {
arr = append(arr, "contract_address")
}
if b.HasHint(HintFunctionSelector) {
arr = append(arr, "function_selector")
}
if b.HasHint(HintLogs) {
arr = append(arr, "logs")
}
if b.HasHint(HintCallData) {
arr = append(arr, "calldata")
}
if b.HasHint(HintHash) {
arr = append(arr, "hash")
}
if b.HasHint(HintSpecialLogs) {
arr = append(arr, "special_logs")
}
if b.HasHint(HintTxHash) {
arr = append(arr, "tx_hash")
}
return json.Marshal(arr)
}
func (b *HintIntent) UnmarshalJSON(data []byte) error {
var arr []string
if err := json.Unmarshal(data, &arr); err != nil {
return err
}
for _, v := range arr {
switch v {
case "contract_address":
b.SetHint(HintContractAddress)
case "function_selector":
b.SetHint(HintFunctionSelector)
case "logs":
b.SetHint(HintLogs)
case "calldata":
b.SetHint(HintCallData)
case "hash":
b.SetHint(HintHash)
case "special_logs":
b.SetHint(HintSpecialLogs)
case "tx_hash":
b.SetHint(HintTxHash)
default:
return ErrInvalidHintIntent
}
}
return nil
}
type Hint struct {
Hash common.Hash `json:"hash"`
Logs []CleanLog `json:"logs"`
Txs []TxHint `json:"txs"`
MevGasPrice *hexutil.Big `json:"mevGasPrice,omitempty"`
GasUsed *hexutil.Uint64 `json:"gasUsed,omitempty"`
}
type TxHint struct {
Hash *common.Hash `json:"hash,omitempty"`
To *common.Address `json:"to,omitempty"`
FunctionSelector *hexutil.Bytes `json:"functionSelector,omitempty"`
CallData *hexutil.Bytes `json:"callData,omitempty"`
}
type SendMevBundleArgs struct {
Version string `json:"version"`
Inclusion MevBundleInclusion `json:"inclusion"`
Body []MevBundleBody `json:"body"`
Validity MevBundleValidity `json:"validity"`
Privacy *MevBundlePrivacy `json:"privacy,omitempty"`
Metadata *MevBundleMetadata `json:"metadata,omitempty"`
}
type MevBundleInclusion struct {
BlockNumber hexutil.Uint64 `json:"block"`
MaxBlock hexutil.Uint64 `json:"maxBlock"`
}
type MevBundleBody struct {
Hash *common.Hash `json:"hash,omitempty"`
Tx *hexutil.Bytes `json:"tx,omitempty"`
Bundle *SendMevBundleArgs `json:"bundle,omitempty"`
CanRevert bool `json:"canRevert,omitempty"`
}
type MevBundleValidity struct {
Refund []RefundConstraint `json:"refund,omitempty"`
RefundConfig []RefundConfig `json:"refundConfig,omitempty"`
}
type RefundConstraint struct {
BodyIdx int `json:"bodyIdx"`
Percent int `json:"percent"`
}
type RefundConfig struct {
Address common.Address `json:"address"`
Percent int `json:"percent"`
}
type MevBundlePrivacy struct {
Hints HintIntent `json:"hints,omitempty"`
Builders []string `json:"builders,omitempty"`
WantRefund *int `json:"wantRefund,omitempty"`
}
type MevBundleMetadata struct {
BundleHash common.Hash `json:"bundleHash,omitempty"`
BodyHashes []common.Hash `json:"bodyHashes,omitempty"`
Signer common.Address `json:"signer,omitempty"`
OriginID string `json:"originId,omitempty"`
ReceivedAt hexutil.Uint64 `json:"receivedAt,omitempty"`
}
type SendMevBundleResponse struct {
BundleHash common.Hash `json:"bundleHash"`
}
type SimMevBundleResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty"`
StateBlock hexutil.Uint64 `json:"stateBlock"`
MevGasPrice hexutil.Big `json:"mevGasPrice"`
Profit hexutil.Big `json:"profit"`
RefundableValue hexutil.Big `json:"refundableValue"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
BodyLogs []SimMevBodyLogs `json:"logs,omitempty"`
}
type SimMevBundleAuxArgs struct {
ParentBlock *rpc.BlockNumberOrHash `json:"parentBlock"`
// override the default values for the block header
BlockNumber *hexutil.Big `json:"blockNumber"`
Coinbase *common.Address `json:"coinbase"`
Timestamp *hexutil.Uint64 `json:"timestamp"`
GasLimit *hexutil.Uint64 `json:"gasLimit"`
BaseFee *hexutil.Big `json:"baseFee"`
Timeout *int64 `json:"timeout"`
}
type SimMevBodyLogs struct {
TxLogs []*types.Log `json:"txLogs,omitempty"`
BundleLogs []SimMevBodyLogs `json:"bundleLogs,omitempty"`
}
type CleanLog struct {
// address of the contract that generated the event
Address common.Address `json:"address"`
// list of topics provided by the contract.
Topics []common.Hash `json:"topics"`
// supplied by the contract, usually ABI-encoded
Data hexutil.Bytes `json:"data"`
}
type SendRefundRecBundleArgs struct {
BlockNumber hexutil.Uint64 `json:"blockNumber"`
Txs []hexutil.Bytes `json:"txs"`
RevertingTxHashes []common.Hash `json:"revertingTxHashes,omitempty"`
RefundPercent *int `json:"refundPercent,omitempty"`
RefundRecipient *common.Address `json:"refundRecipient,omitempty"`
}