Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🩹 mev: cancel bundle response #22

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions pkg/mev/bundle_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func (s *Client) SendBundle(
blockNumber uint64,
txs ...*types.Transaction,
) (SendBundleResponse, error) {
return s.sendBundle(ctx, false, uuid, blockNumber, txs...)
return s.sendBundle(ctx, uuid, blockNumber, txs...)
}

func (s *Client) CancelBundle(
ctx context.Context, bundleUUID string,
) error {
if s.cancelBySendBundle {
if _, err := s.sendBundle(ctx, true, &bundleUUID, 0); err != nil {
if _, err := s.sendBundle(ctx, &bundleUUID, 0); err != nil {
return fmt.Errorf("cancel by send bundle error: %w", err)
}
return nil
Expand Down Expand Up @@ -92,6 +92,12 @@ func (s *Client) CancelBundle(
// do
var errResp SendBundleError
switch s.senderType {
case BundleSenderTypeFlashbot:
resp, err := doRequest[FlashbotCancelBundleResponse](s.c, httpReq, headers...)
if err != nil {
return err
}
errResp = resp.Error
case BundleSenderTypeTitan:
resp, err := doRequest[TitanCancelBundleResponse](s.c, httpReq, headers...)
if err != nil {
Expand All @@ -116,7 +122,6 @@ func (s *Client) CancelBundle(

func (s *Client) sendBundle(
ctx context.Context,
isCancel bool,
uuid *string,
blockNumber uint64,
txs ...*types.Transaction,
Expand Down Expand Up @@ -151,26 +156,9 @@ func (s *Client) sendBundle(
return SendBundleResponse{}, fmt.Errorf("new http request error: %w", err)
}

var resp SendBundleResponse
if !isCancel {
resp, err = doRequest[SendBundleResponse](s.c, httpReq, headers...)
if err != nil {
return SendBundleResponse{}, err
}
} else {
switch s.senderType {
case BundleSenderTypeFlashbot:
r, err := doRequest[FlashbotCancelBundleResponse](s.c, httpReq, headers...)
if err != nil {
return SendBundleResponse{}, err
}
resp = r.ToSendBundleResponse()
default:
resp, err = doRequest[SendBundleResponse](s.c, httpReq, headers...)
if err != nil {
return SendBundleResponse{}, err
}
}
resp, err := doRequest[SendBundleResponse](s.c, httpReq, headers...)
if err != nil {
return SendBundleResponse{}, err
}

if len(resp.Error.Messange) != 0 {
Expand Down Expand Up @@ -200,9 +188,9 @@ type SendBundleRequest struct {

type SendBundleParams struct {
// Array[String], A list of signed transactions to execute in an atomic bundle
Txs []string `json:"txs"`
Txs []string `json:"txs,omitempty"`
// String, a hex encoded block number for which this bundle is valid on
BlockNumber string `json:"blockNumber"`
BlockNumber string `json:"blockNumber,omitempty"`
// (Optional) Number, the minimum timestamp for which this bundle is valid, in seconds since the unix epoch
MinTimestamp *uint64 `json:"minTimestamp,omitempty"`
// (Optional) Number, the maximum timestamp for which this bundle is valid, in seconds since the unix epoch
Expand Down
14 changes: 14 additions & 0 deletions pkg/mev/bundle_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,17 @@ func TestUnmarshal(t *testing.T) {

t.Logf("%+v", resp)
}

func TestCancelBeaver(t *testing.T) {
t.Skip()
var (
endpoint = "https://rpc.beaverbuild.org"
ctx = context.Background()
client = http.DefaultClient
bundleUUID = uuid.New().String()
)

sender := mev.NewClient(client, endpoint, nil, true, mev.BundleSenderTypeBeaver)

require.NoError(t, sender.CancelBundle(ctx, bundleUUID))
}
Loading