Skip to content

Commit

Permalink
feat: add getfrom
Browse files Browse the repository at this point in the history
  • Loading branch information
datluongductuan committed Apr 8, 2024
1 parent a6432b0 commit ca4c34d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
10 changes: 10 additions & 0 deletions pkg/mev/blxr_bundle_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion pkg/mev/bundle_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions pkg/mev/bundle_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions pkg/mev/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -35,6 +36,7 @@ const (
ETHSendBundleMethod = "eth_sendBundle"
EthCallBundleMethod = "eth_callBundle"
ETHCancelBundleMethod = "eth_cancelBundle"
ETHEstimateGasBundleMethod = "eth_estimateGasBundle"
MevSendBundleMethod = "mev_sendBundle"
MaxBlockFromTarget = 3
)
Expand All @@ -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,
Expand Down Expand Up @@ -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
}

0 comments on commit ca4c34d

Please sign in to comment.