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 5fc56df
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 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(
ctx context.Context,

Check warning on line 38 in pkg/mev/blxr_bundle_sender.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
messages []ethereum.CallMsg,

Check warning on line 39 in pkg/mev/blxr_bundle_sender.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

unused-parameter: parameter 'messages' seems to be unused, consider removing or renaming it as _ (revive)
overrides *map[common.Address]gethclient.OverrideAccount,

Check warning on line 40 in pkg/mev/blxr_bundle_sender.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

unused-parameter: parameter 'overrides' seems to be unused, consider removing or renaming it as _ (revive)
) ([]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
3 changes: 2 additions & 1 deletion pkg/mev/bundle_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,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 5fc56df

Please sign in to comment.