From a1d0d158318722ab52eab24726afa15a160b4892 Mon Sep 17 00:00:00 2001 From: Dat Luong <105619094+datluongductuan@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:14:32 +0700 Subject: [PATCH] feat: implement logic for mevblocker (#59) * feat: implement logic for mevblocker * fix: lint --- pkg/mev/backrun_public_sender_test.go | 41 +++++++++++++++++++++++++++ pkg/mev/pkg.go | 1 + pkg/types/pendingtx.go | 12 +++++--- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 pkg/mev/backrun_public_sender_test.go diff --git a/pkg/mev/backrun_public_sender_test.go b/pkg/mev/backrun_public_sender_test.go new file mode 100644 index 0000000..9fa50b4 --- /dev/null +++ b/pkg/mev/backrun_public_sender_test.go @@ -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) +} diff --git a/pkg/mev/pkg.go b/pkg/mev/pkg.go index 1e1da31..508c44f 100644 --- a/pkg/mev/pkg.go +++ b/pkg/mev/pkg.go @@ -29,6 +29,7 @@ const ( BundleSenderTypeAll BundleSenderTypeMevShare BundleSenderTypeBackrunPublic + BundleSenderTypeMevBlocker ) const ( diff --git a/pkg/types/pendingtx.go b/pkg/types/pendingtx.go index 9b3d4fe..6d84438 100644 --- a/pkg/types/pendingtx.go +++ b/pkg/types/pendingtx.go @@ -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 { @@ -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 {