From ca4c34d3fc8bb6252626512173b8a6d0229fb744 Mon Sep 17 00:00:00 2001 From: Dat Luong Date: Mon, 8 Apr 2024 16:41:23 +0700 Subject: [PATCH] feat: add getfrom --- pkg/mev/blxr_bundle_sender.go | 10 ++++++++++ pkg/mev/bundle_sender.go | 3 ++- pkg/mev/bundle_sender_test.go | 9 ++++++--- pkg/mev/pkg.go | 12 ++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/pkg/mev/blxr_bundle_sender.go b/pkg/mev/blxr_bundle_sender.go index 1e12819..09d7c2e 100644 --- a/pkg/mev/blxr_bundle_sender.go +++ b/pkg/mev/blxr_bundle_sender.go @@ -9,8 +9,10 @@ import ( "net/http" "strconv" + "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/ethclient/gethclient" "github.com/flashbots/mev-share-node/mevshare" ) @@ -32,6 +34,14 @@ type BloxrouteClient struct { enabledBuilders []BlxrBuilder } +func (s *BloxrouteClient) EstimateBundleGas( + _ context.Context, + _ []ethereum.CallMsg, + _ *map[common.Address]gethclient.OverrideAccount, +) ([]uint64, error) { + return nil, nil +} + func (s *BloxrouteClient) MevSimulateBundle( _ uint64, _ common.Hash, diff --git a/pkg/mev/bundle_sender.go b/pkg/mev/bundle_sender.go index 1600f8a..28d6008 100644 --- a/pkg/mev/bundle_sender.go +++ b/pkg/mev/bundle_sender.go @@ -135,6 +135,7 @@ func (s *Client) flashbotBackrunSendBundle( } func (s *Client) EstimateBundleGas( + _ context.Context, messages []ethereum.CallMsg, overrides *map[common.Address]gethclient.OverrideAccount, ) ([]uint64, error) { @@ -146,7 +147,7 @@ func (s *Client) EstimateBundleGas( var gasEstimateCost []hexutil.Uint64 err := s.ethClient.Client().Call( - &gasEstimateCost, "eth_estimateGasBundle", + &gasEstimateCost, ETHEstimateGasBundleMethod, map[string]interface{}{ "transactions": bundles, }, "latest", overrides, diff --git a/pkg/mev/bundle_sender_test.go b/pkg/mev/bundle_sender_test.go index 7897fc8..743475d 100644 --- a/pkg/mev/bundle_sender_test.go +++ b/pkg/mev/bundle_sender_test.go @@ -66,7 +66,8 @@ func TestSendBundle(t *testing.T) { t.Log("new tx", signedTx.Hash().String()) uuid := uuid.NewString() - sender := mev.NewClient(client, endpoint, privateKey, false, mev.BundleSenderTypeFlashbot) + sender, err := mev.NewClient(client, endpoint, privateKey, false, mev.BundleSenderTypeFlashbot) + require.NoError(t, err) resp, err := sender.SendBundle(ctx, &uuid, blockNumber+12, signedTx) require.NoError(t, err) // sepolia: code: [-32000], message: [internal server error] @@ -95,7 +96,8 @@ func TestCancelBeaver(t *testing.T) { bundleUUID = uuid.New().String() ) - sender := mev.NewClient(client, endpoint, nil, true, mev.BundleSenderTypeBeaver) + sender, err := mev.NewClient(client, endpoint, nil, true, mev.BundleSenderTypeBeaver) + require.NoError(t, err) require.NoError(t, sender.CancelBundle(ctx, bundleUUID)) } @@ -131,8 +133,9 @@ func Test_SimulateBundle(t *testing.T) { var ( simulationEndpoint = "http://localhost:8545" - client = mev.NewClient(http.DefaultClient, simulationEndpoint, nil, false, mev.BundleSenderTypeFlashbot) + client, err = mev.NewClient(http.DefaultClient, simulationEndpoint, nil, false, mev.BundleSenderTypeFlashbot) ) + require.NoError(t, err) simulationResponse, err := client.SimulateBundle(context.Background(), uint64(blockNumber), txs...) require.NoError(t, err) diff --git a/pkg/mev/pkg.go b/pkg/mev/pkg.go index 519d31f..5da50bd 100644 --- a/pkg/mev/pkg.go +++ b/pkg/mev/pkg.go @@ -13,6 +13,7 @@ import ( "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/ethclient/gethclient" "github.com/flashbots/mev-share-node/mevshare" ) @@ -35,6 +36,7 @@ const ( ETHSendBundleMethod = "eth_sendBundle" EthCallBundleMethod = "eth_callBundle" ETHCancelBundleMethod = "eth_cancelBundle" + ETHEstimateGasBundleMethod = "eth_estimateGasBundle" MevSendBundleMethod = "mev_sendBundle" MaxBlockFromTarget = 3 ) @@ -57,6 +59,11 @@ type IBundleSender interface { ctx context.Context, bundleUUID string, ) error SimulateBundle(ctx context.Context, blockNumber uint64, txs ...*types.Transaction) (SendBundleResponse, error) + EstimateBundleGas( + ctx context.Context, + messages []ethereum.CallMsg, + overrides *map[common.Address]gethclient.OverrideAccount, + ) ([]uint64, error) MevSimulateBundle( blockNumber uint64, pendingTxHash common.Hash, @@ -196,3 +203,8 @@ func ToCallArg(msg ethereum.CallMsg) interface{} { } return arg } + +func GetFrom(tx *types.Transaction) (common.Address, error) { + from, err := types.Sender(types.LatestSignerForChainID(tx.ChainId()), tx) + return from, err +}