Skip to content

Commit

Permalink
fix: mev sendbundle encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
datluongductuan committed Jun 7, 2024
1 parent 28275d7 commit 70183ef
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/mev/blxr_bundle_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (p *BLXRSubmitBundleParams) SetTransactions(txs ...*types.Transaction) *BLX

transactions := make([]string, 0, len(txs))
for _, tx := range txs {
transactions = append(transactions, "0x"+txToRlp(tx))
transactions = append(transactions, "0x"+TxToRlp(tx))
}

p.Transaction = transactions
Expand Down
12 changes: 8 additions & 4 deletions pkg/mev/bundle_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ func (s *Client) flashbotBackrunSendBundle(
return nil, fmt.Errorf("mev share client is nil")
}

encodedTx := "0x" + txToRlp(tx)
txBytes := hexutil.Bytes(encodedTx)
rlpEncodedTx, err := tx.MarshalBinary()
if err != nil {
return nil, err
}

txBytes := hexutil.Bytes(rlpEncodedTx)
// Define the bundle transactions
txs := []mevshare.MevBundleBody{
{
Expand Down Expand Up @@ -146,7 +150,7 @@ func (s *Client) MevSimulateBundle(
return nil, fmt.Errorf("mev share client is nil")
}

encodedTx := "0x" + txToRlp(tx)
encodedTx := "0x" + TxToRlp(tx)
txBytes := hexutil.Bytes(encodedTx)
// Define the bundle transactions
txs := []mevshare.MevBundleBody{
Expand Down Expand Up @@ -429,7 +433,7 @@ func (p *SendBundleParams) SetTransactions(txs ...*types.Transaction) *SendBundl

transactions := make([]string, 0, len(txs))
for _, tx := range txs {
transactions = append(transactions, "0x"+txToRlp(tx))
transactions = append(transactions, "0x"+TxToRlp(tx))
}

p.Txs = transactions
Expand Down
61 changes: 61 additions & 0 deletions pkg/mev/bundle_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import (

"github.com/KyberNetwork/tradinglib/pkg/convert"
"github.com/KyberNetwork/tradinglib/pkg/mev"
"github.com/duoxehyon/mev-share-go/rpc"
"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/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/flashbots/mev-share-node/mevshare"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -165,3 +168,61 @@ func Test_SimulateBundle(t *testing.T) {
simulationResponse.Result.BundleHash,
)
}

func TestMevSendBundle(t *testing.T) {
t.Skip()

ethClient, err := ethclient.Dial("https://ethereum-rpc.publicnode.com")
require.NoError(t, err)

blockNumber, err := ethClient.BlockNumber(context.Background())
require.NoError(t, err)
t.Log("blockNumber", blockNumber)

// Transaction hashes you want to fetch from the node
txHashes := []string{
"0x2e038916d175d9028c87d59e33f79ac96cb487e90aad6cd501dc9675b64d7245",
}
tx, isPending, err := ethClient.TransactionByHash(context.Background(), common.HexToHash(txHashes[0]))
require.NoError(t, err)
require.False(t, isPending)

// Serialize the transaction to RLP
rlpEncodedTx, err := tx.MarshalBinary()
if err != nil {
log.Fatalf("Failed to encode transaction: %v", err)
}

// Flashbots header signing key
fbSigningKey, err := crypto.GenerateKey()
if err != nil {
log.Fatal(err)
}

// Initialize the client
rpcClient := rpc.NewClient("https://relay.flashbots.net", fbSigningKey)

//encodedTx := "0x" + mev.TxToRlp(tx)

Check failure on line 205 in pkg/mev/bundle_sender_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
txBytes := hexutil.Bytes(rlpEncodedTx)

// Define the bundle transactions
txns := []mevshare.MevBundleBody{
{
Tx: &txBytes,
},
}
inclusion := mevshare.MevBundleInclusion{
BlockNumber: hexutil.Uint64(blockNumber + 1),
}
// Make the bundle
req := mevshare.SendMevBundleArgs{
Body: txns,
Inclusion: inclusion,
}

// Send bundle
res, err := rpcClient.SendBundle(req)
assert.Nil(t, err)

t.Log(res.BundleHash.String(), "bundleHash")
}
2 changes: 1 addition & 1 deletion pkg/mev/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var defaultHeaders = [][2]string{ // nolint: gochecknoglobals
{"Accept", "application/json"},
}

func txToRlp(tx *types.Transaction) string {
func TxToRlp(tx *types.Transaction) string {
var buff bytes.Buffer
_ = tx.EncodeRLP(&buff)

Expand Down

0 comments on commit 70183ef

Please sign in to comment.