diff --git a/pkg/mev/blxr_bundle_sender.go b/pkg/mev/blxr_bundle_sender.go index be0fe4f..b24cfa9 100644 --- a/pkg/mev/blxr_bundle_sender.go +++ b/pkg/mev/blxr_bundle_sender.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/flashbots/mev-share-node/mevshare" ) type BlxrBuilder string @@ -31,6 +32,10 @@ type BloxrouteClient struct { enabledBuilders []BlxrBuilder } +func (s *BloxrouteClient) MevSimulateBundle(_ uint64, _ common.Hash, _ *types.Transaction) (*mevshare.SimMevBundleResponse, error) { + return nil, fmt.Errorf("method not support") +} + // NewBloxrouteClient set flashbotKey to nil if you don't want to send to flashbot builders // With BuilderAll still need to add the flashbot key & the flashbot builder separately // https://docs.bloxroute.com/apis/mev-solution/bundle-submission diff --git a/pkg/mev/bundle_sender.go b/pkg/mev/bundle_sender.go index a28593e..d86f029 100644 --- a/pkg/mev/bundle_sender.go +++ b/pkg/mev/bundle_sender.go @@ -106,18 +106,62 @@ func (s *Client) flashbotBackrunSendBundle( } inclusion := mevshare.MevBundleInclusion{ BlockNumber: hexutil.Uint64(blockNumber), + MaxBlock: hexutil.Uint64(blockNumber + MaxBlockFromTarget), } // Make the bundle req := mevshare.SendMevBundleArgs{ Body: txs, Inclusion: inclusion, + // share bundle data in increase chance of inclusion + // https://docs.flashbots.net/flashbots-mev-share/searchers/sending-bundles#share-bundle-data + Privacy: &mevshare.MevBundlePrivacy{ + Hints: mevshare.HintTxHash, + }, } // Send bundle res, err := s.mevShareClient.SendBundle(req) return res, err } +func (s *Client) MevSimulateBundle( + blockNumber uint64, + pendingTxHash common.Hash, + tx *types.Transaction, +) (*mevshare.SimMevBundleResponse, error) { + if s.mevShareClient == nil { + return nil, fmt.Errorf("mev share client is nil") + } + + encodedTx := "0x" + txToRlp(tx) + txBytes := hexutil.Bytes(encodedTx) + // Define the bundle transactions + txs := []mevshare.MevBundleBody{ + { + Hash: &pendingTxHash, + }, + { + Tx: &txBytes, + }, + } + inclusion := mevshare.MevBundleInclusion{ + BlockNumber: hexutil.Uint64(blockNumber), + MaxBlock: hexutil.Uint64(blockNumber + MaxBlockFromTarget), + } + + // Make the bundle + req := mevshare.SendMevBundleArgs{ + Body: txs, + Inclusion: inclusion, + Privacy: &mevshare.MevBundlePrivacy{ + Hints: mevshare.HintTxHash, + }, + } + // Send bundle + res, err := s.mevShareClient.SimBundle(req, mevshare.SimMevBundleAuxArgs{}) + return res, err +} + func (s *Client) ethBackrunSendBundle( ctx context.Context, uuid *string, diff --git a/pkg/mev/pkg.go b/pkg/mev/pkg.go index 43f2711..9d39849 100644 --- a/pkg/mev/pkg.go +++ b/pkg/mev/pkg.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/flashbots/mev-share-node/mevshare" ) type BundleSenderType int @@ -33,6 +34,7 @@ const ( EthCallBundleMethod = "eth_callBundle" ETHCancelBundleMethod = "eth_cancelBundle" MevSendBundleMethod = "mev_sendBundle" + MaxBlockFromTarget = 3 ) type IBundleSender interface { @@ -53,6 +55,10 @@ type IBundleSender interface { ctx context.Context, bundleUUID string, ) error SimulateBundle(ctx context.Context, blockNumber uint64, txs ...*types.Transaction) (SendBundleResponse, error) + MevSimulateBundle( + blockNumber uint64, + pendingTxHash common.Hash, + tx *types.Transaction) (*mevshare.SimMevBundleResponse, error) GetSenderType() BundleSenderType }