Skip to content

Commit

Permalink
feat: add MevSimulateBundle iface
Browse files Browse the repository at this point in the history
  • Loading branch information
datluongductuan committed Mar 14, 2024
1 parent 5d62f89 commit 4d85830
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/mev/blxr_bundle_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,6 +32,10 @@ type BloxrouteClient struct {
enabledBuilders []BlxrBuilder
}

func (s *BloxrouteClient) MevSimulateBundle(_ uint64, _ common.Hash, _ *types.Transaction) (*mevshare.SimMevBundleResponse, error) {

Check failure on line 35 in pkg/mev/blxr_bundle_sender.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

line is 132 characters (lll)
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
Expand Down
44 changes: 44 additions & 0 deletions pkg/mev/bundle_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions pkg/mev/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +34,7 @@ const (
EthCallBundleMethod = "eth_callBundle"
ETHCancelBundleMethod = "eth_cancelBundle"
MevSendBundleMethod = "mev_sendBundle"
MaxBlockFromTarget = 3
)

type IBundleSender interface {
Expand All @@ -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
}

Expand Down

0 comments on commit 4d85830

Please sign in to comment.