Skip to content

Commit

Permalink
Merge pull request #50 from KyberNetwork/fix/mev_sendBundle
Browse files Browse the repository at this point in the history
fix: mev sendbundle encoding
  • Loading branch information
datluongductuan authored Jun 7, 2024
2 parents 0b3dce1 + 5eebe21 commit d710595
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
8 changes: 6 additions & 2 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
60 changes: 60 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,60 @@ 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)

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")
}

0 comments on commit d710595

Please sign in to comment.