Skip to content

Commit

Permalink
feat: clean etherman
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniRamirezM committed Jul 1, 2024
1 parent a9149b8 commit a750d45
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 280 deletions.
58 changes: 3 additions & 55 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"time"

ethmanTypes "github.com/0xPolygon/cdk/aggregator/ethmantypes"
"github.com/0xPolygon/cdk/etherman/etherscan"
"github.com/0xPolygon/cdk/etherman/ethgasstation"
"github.com/0xPolygon/cdk/etherman/smartcontracts/dataavailabilityprotocol"
"github.com/0xPolygon/cdk/etherman/smartcontracts/oldpolygonzkevm"
"github.com/0xPolygon/cdk/etherman/smartcontracts/oldpolygonzkevmglobalexitroot"
Expand Down Expand Up @@ -152,11 +150,6 @@ type L1Config struct {
GlobalExitRootManagerAddr common.Address `json:"polygonZkEVMGlobalExitRootAddress"`
}

type externalGasProviders struct {
MultiGasProvider bool
Providers []ethereum.GasPricer
}

// Client is a simple implementation of EtherMan.
type Client struct {
EthClient ethereumClient
Expand All @@ -171,8 +164,6 @@ type Client struct {

RollupID uint32

GasProviders externalGasProviders

l1Cfg L1Config
cfg Config
auth map[common.Address]bind.TransactOpts // empty in case of read-only client
Expand Down Expand Up @@ -215,17 +206,6 @@ func NewClient(cfg Config, l1Config L1Config) (*Client, error) {
var scAddresses []common.Address
scAddresses = append(scAddresses, l1Config.ZkEVMAddr, l1Config.RollupManagerAddr, l1Config.GlobalExitRootManagerAddr)

gProviders := []ethereum.GasPricer{ethClient}
if cfg.EthermanConfig.MultiGasProvider {
if cfg.EthermanConfig.Etherscan.ApiKey == "" {
log.Info("No ApiKey provided for etherscan. Ignoring provider...")
} else {
log.Info("ApiKey detected for etherscan")
gProviders = append(gProviders, etherscan.NewEtherscanService(cfg.EthermanConfig.Etherscan.ApiKey))
}
gProviders = append(gProviders, ethgasstation.NewEthGasStationService())
}

// Get RollupID
rollupID, err := rollupManager.RollupAddressToID(&bind.CallOpts{Pending: false}, l1Config.ZkEVMAddr)
if err != nil {
Expand All @@ -242,13 +222,9 @@ func NewClient(cfg Config, l1Config L1Config) (*Client, error) {
GlobalExitRootManager: globalExitRoot,
SCAddresses: scAddresses,
RollupID: rollupID,
GasProviders: externalGasProviders{
MultiGasProvider: cfg.EthermanConfig.MultiGasProvider,
Providers: gProviders,
},
l1Cfg: l1Config,
cfg: cfg,
auth: map[common.Address]bind.TransactOpts{},
l1Cfg: l1Config,
cfg: cfg,
auth: map[common.Address]bind.TransactOpts{},
}

if cfg.IsValidiumMode {
Expand Down Expand Up @@ -1475,9 +1451,6 @@ func (etherMan *Client) ApprovePol(ctx context.Context, account common.Address,
if err == ErrNotFound {
return nil, errors.New("can't find account private key to sign tx")
}
if etherMan.GasProviders.MultiGasProvider {
opts.GasPrice = etherMan.GetL1GasPrice(ctx)
}
tx, err := etherMan.Pol.Approve(&opts, etherMan.l1Cfg.ZkEVMAddr, polAmount)
if err != nil {
if parsedErr, ok := tryParseError(err); ok {
Expand Down Expand Up @@ -1513,22 +1486,6 @@ func (etherMan *Client) GetL2ChainID() (uint64, error) {
return chainID, nil
}

// GetL1GasPrice gets the l1 gas price
func (etherMan *Client) GetL1GasPrice(ctx context.Context) *big.Int {
// Get gasPrice from providers
gasPrice := big.NewInt(0)
for i, prov := range etherMan.GasProviders.Providers {
gp, err := prov.SuggestGasPrice(ctx)
if err != nil {
log.Warnf("error getting gas price from provider %d. Error: %s", i+1, err.Error())
} else if gasPrice.Cmp(gp) == -1 { // gasPrice < gp
gasPrice = gp
}
}
log.Debug("gasPrice chose: ", gasPrice)
return gasPrice
}

// SendTx sends a tx to L1
func (etherMan *Client) SendTx(ctx context.Context, tx *types.Transaction) error {
return etherMan.EthClient.SendTransaction(ctx, tx)
Expand All @@ -1539,15 +1496,6 @@ func (etherMan *Client) CurrentNonce(ctx context.Context, account common.Address
return etherMan.EthClient.NonceAt(ctx, account, nil)
}

// SuggestedGasPrice returns the suggest nonce for the network at the moment
func (etherMan *Client) SuggestedGasPrice(ctx context.Context) (*big.Int, error) {
suggestedGasPrice := etherMan.GetL1GasPrice(ctx)
if suggestedGasPrice.Cmp(big.NewInt(0)) == 0 {
return nil, errors.New("failed to get the suggested gas price")
}
return suggestedGasPrice, nil
}

// EstimateGas returns the estimated gas for the tx
func (etherMan *Client) EstimateGas(ctx context.Context, from common.Address, to *common.Address, value *big.Int, data []byte) (uint64, error) {
return etherMan.EthClient.EstimateGas(ctx, ethereum.CallMsg{
Expand Down
82 changes: 0 additions & 82 deletions etherman/etherscan/etherscan.go

This file was deleted.

39 changes: 0 additions & 39 deletions etherman/etherscan/etherscan_test.go

This file was deleted.

67 changes: 0 additions & 67 deletions etherman/ethgasstation/ethgasstation.go

This file was deleted.

37 changes: 0 additions & 37 deletions etherman/ethgasstation/ethgasstation_test.go

This file was deleted.

0 comments on commit a750d45

Please sign in to comment.