diff --git a/pkg/mev/bundle_sender.go b/pkg/mev/bundle_sender.go index 629914a..4192f70 100644 --- a/pkg/mev/bundle_sender.go +++ b/pkg/mev/bundle_sender.go @@ -55,6 +55,56 @@ func (s *Client) SendBundle( return s.sendBundle(ctx, ETHSendBundleMethod, uuid, blockNumber, txs...) } +func (s *Client) SendBackrunBundle( + ctx context.Context, + uuid *string, + blockNumber uint64, + pendingTxHash common.Hash, + txs ...*types.Transaction, +) (SendBundleResponse, error) { + req := SendBundleRequest{ + ID: SendBundleID, + JSONRPC: JSONRPC2, + Method: ETHSendBundleMethod, + } + p := new(SendBundleParams).SetBlockNumber(blockNumber).SetTransactions(txs...).SetPendingTxHash(pendingTxHash) + if uuid != nil { + p.SetUUID(*uuid, s.senderType) + } + req.Params = append(req.Params, p) + + reqBody, err := json.Marshal(req) + if err != nil { + return SendBundleResponse{}, fmt.Errorf("marshal json error: %w", err) + } + + var headers [][2]string + if s.flashbotKey != nil { + signature, err := requestSignature(s.flashbotKey, reqBody) + if err != nil { + return SendBundleResponse{}, fmt.Errorf("sign flashbot request error: %w", err) + } + headers = append(headers, [2]string{"X-Flashbots-Signature", signature}) + } + + httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, s.endpoint, bytes.NewBuffer(reqBody)) + if err != nil { + return SendBundleResponse{}, fmt.Errorf("new http request error: %w", err) + } + + resp, err := doRequest[SendBundleResponse](s.c, httpReq, headers...) + if err != nil { + return SendBundleResponse{}, err + } + + if len(resp.Error.Messange) != 0 { + return SendBundleResponse{}, fmt.Errorf("response error, code: [%d], message: [%s]", + resp.Error.Code, resp.Error.Messange) + } + + return resp, nil +} + func (s *Client) CancelBundle( ctx context.Context, bundleUUID string, ) error { diff --git a/pkg/mev/pkg.go b/pkg/mev/pkg.go index f6c2edb..056a948 100644 --- a/pkg/mev/pkg.go +++ b/pkg/mev/pkg.go @@ -9,6 +9,7 @@ import ( "io" "net/http" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" ) @@ -40,6 +41,13 @@ type IBundleSender interface { blockNumber uint64, tx ...*types.Transaction, ) (SendBundleResponse, error) + SendBackrunBundle( + ctx context.Context, + uuid *string, + blockNumber uint64, + pendingTxHash common.Hash, + tx ...*types.Transaction, + ) (SendBundleResponse, error) CancelBundle( ctx context.Context, bundleUUID string, ) error