Skip to content

Commit

Permalink
feat: implement logic for mevblocker (#59)
Browse files Browse the repository at this point in the history
* feat: implement logic for mevblocker

* fix: lint
  • Loading branch information
datluongductuan authored Jun 20, 2024
1 parent 880102b commit a1d0d15
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
41 changes: 41 additions & 0 deletions pkg/mev/backrun_public_sender_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package mev_test

import (
"context"
"net/http"
"testing"
"time"

"github.com/KyberNetwork/tradinglib/pkg/mev"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"
)

func TestNewBackrunPublicClient(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)

httpCl := http.Client{Timeout: time.Second * 5}
// Initialize the client
senderClient := mev.NewBackrunPublicClient(&httpCl, "https://rpc.mevblocker.io", nil, mev.BundleSenderTypeMevBlocker)

pendingTXhash := common.HexToHash("0x79d48b1a25d7af0d815997d2ce3a127560080971c5ea98ca5a32424f604e09fb")
resp, err := senderClient.SendBackrunBundle(context.Background(), nil, blockNumber, pendingTXhash, []string{}, tx)
t.Log("resp", resp)
t.Log("err", err)
}
1 change: 1 addition & 0 deletions pkg/mev/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
BundleSenderTypeAll
BundleSenderTypeMevShare
BundleSenderTypeBackrunPublic
BundleSenderTypeMevBlocker
)

const (
Expand Down
12 changes: 8 additions & 4 deletions pkg/types/pendingtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ type MinedBlock struct {
}

func (m Message) GetAllLogs() []*types.Log {
if m.Source == FlashbotMempool {
switch m.Source {
case FlashbotMempool:
if m.FlashbotMevshareEvent != nil {
results := make([]*types.Log, 0, len(m.FlashbotMevshareEvent.Logs))
for _, log := range m.FlashbotMevshareEvent.Logs {
Expand All @@ -117,12 +118,15 @@ func (m Message) GetAllLogs() []*types.Log {
}
return results
}
case MevBlockerMempool, PublicMempool:
if m.InternalTx == nil {
return m.InternalTx.getLogs()
}
default:
return nil
}

// public mempool case
logs := m.InternalTx.getLogs()
return logs
return nil
}

func (c CallFrame) getLogs() []*types.Log {
Expand Down

0 comments on commit a1d0d15

Please sign in to comment.