Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion token-price-oracle/client/l2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type L2Client struct {
opts *bind.TransactOpts
signer *Signer
externalSign bool
gasFeeCap *big.Int // Fixed gas fee cap (nil means use dynamic)
gasTipCap *big.Int // Fixed gas tip cap (nil means use dynamic)
}

// NewL2Client creates new L2 client
Expand Down Expand Up @@ -50,6 +52,16 @@ func NewL2Client(rpcURL string, cfg *config.Config) (*L2Client, error) {
externalSign: cfg.ExternalSign,
}

// Set fixed gas fee if configured (0 means use dynamic)
if cfg.GasFeeCap > 0 {
l2Client.gasFeeCap = big.NewInt(int64(cfg.GasFeeCap))
log.Info("Using fixed gas fee cap", "gasFeeCap", cfg.GasFeeCap)
}
if cfg.GasTipCap > 0 {
l2Client.gasTipCap = big.NewInt(int64(cfg.GasTipCap))
log.Info("Using fixed gas tip cap", "gasTipCap", cfg.GasTipCap)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

if cfg.ExternalSign {
// External sign mode
rsaPriv, err := externalsign.ParseRsaPrivateKey(cfg.ExternalSignRsaPriv)
Expand Down Expand Up @@ -129,7 +141,7 @@ func (c *L2Client) GetClient() *ethclient.Client {
// Returns a new instance to prevent concurrent modification
func (c *L2Client) GetOpts() *bind.TransactOpts {
// Return a copy to prevent shared state issues
return &bind.TransactOpts{
opts := &bind.TransactOpts{
From: c.opts.From,
Nonce: c.opts.Nonce,
Signer: c.opts.Signer,
Expand All @@ -141,6 +153,14 @@ func (c *L2Client) GetOpts() *bind.TransactOpts {
Context: c.opts.Context,
NoSend: c.opts.NoSend,
}
// Override with fixed gas fee if configured
if c.gasFeeCap != nil {
opts.GasFeeCap = c.gasFeeCap
}
if c.gasTipCap != nil {
opts.GasTipCap = c.gasTipCap
}
return opts
}

// GetBalance returns account balance
Expand All @@ -167,3 +187,13 @@ func (c *L2Client) GetSigner() *Signer {
func (c *L2Client) GetChainID() *big.Int {
return c.chainID
}

// GetFixedGasFeeCap returns the fixed gas fee cap (nil if not configured)
func (c *L2Client) GetFixedGasFeeCap() *big.Int {
return c.gasFeeCap
}

// GetFixedGasTipCap returns the fixed gas tip cap (nil if not configured)
func (c *L2Client) GetFixedGasTipCap() *big.Int {
return c.gasTipCap
}
44 changes: 28 additions & 16 deletions token-price-oracle/client/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,38 @@ func (s *Signer) CreateAndSignTx(
return nil, fmt.Errorf("failed to get nonce: %w", err)
}

// Get gas tip cap
tip, err := client.GetClient().SuggestGasTipCap(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get gas tip cap: %w", err)
}

// Get base fee from latest block
head, err := client.GetClient().HeaderByNumber(ctx, nil)
if err != nil {
return nil, fmt.Errorf("failed to get block header: %w", err)
// Get gas tip cap (use fixed if configured, otherwise dynamic)
var tip *big.Int
if fixedTip := client.GetFixedGasTipCap(); fixedTip != nil {
tip = fixedTip
log.Debug("Using fixed gas tip cap", "tip", tip)
} else {
tip, err = client.GetClient().SuggestGasTipCap(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get gas tip cap: %w", err)
}
}

// Get gas fee cap (use fixed if configured, otherwise dynamic)
var gasFeeCap *big.Int
if head.BaseFee != nil {
gasFeeCap = new(big.Int).Add(
tip,
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
)
if fixedFeeCap := client.GetFixedGasFeeCap(); fixedFeeCap != nil {
gasFeeCap = fixedFeeCap
log.Debug("Using fixed gas fee cap", "gasFeeCap", gasFeeCap)
} else {
gasFeeCap = new(big.Int).Set(tip)
// Get base fee from latest block
head, err := client.GetClient().HeaderByNumber(ctx, nil)
if err != nil {
return nil, fmt.Errorf("failed to get block header: %w", err)
}

if head.BaseFee != nil {
gasFeeCap = new(big.Int).Add(
tip,
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
)
} else {
gasFeeCap = new(big.Int).Set(tip)
}
}

// Estimate gas
Expand Down
8 changes: 8 additions & 0 deletions token-price-oracle/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ type Config struct {
LogFileMaxSize int
LogFileMaxAge int
LogCompress bool

// Gas fee (optional - if set, use fixed values instead of dynamic)
GasFeeCap uint64 // Fixed gas fee cap in wei (0 means use dynamic)
GasTipCap uint64 // Fixed gas tip cap in wei (0 means use dynamic)
}

// LoadConfig loads configuration from cli.Context
Expand All @@ -110,6 +114,10 @@ func LoadConfig(ctx *cli.Context) (*Config, error) {
LogFileMaxSize: ctx.Int(flags.LogFileMaxSizeFlag.Name),
LogFileMaxAge: ctx.Int(flags.LogFileMaxAgeFlag.Name),
LogCompress: ctx.Bool(flags.LogCompressFlag.Name),

// Gas fee (0 means use dynamic)
GasFeeCap: ctx.Uint64(flags.GasFeeCapFlag.Name),
GasTipCap: ctx.Uint64(flags.GasTipCapFlag.Name),
}
Comment thread
curryxbo marked this conversation as resolved.

// Parse token registry address (optional)
Expand Down
19 changes: 19 additions & 0 deletions token-price-oracle/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ var (
Usage: "The RSA private key for external sign",
EnvVar: prefixEnvVar("EXTERNAL_SIGN_RSA_PRIV"),
}

// Gas fee flags (optional - if set, use fixed values instead of dynamic)
GasFeeCapFlag = cli.Uint64Flag{
Name: "gas-fee-cap",
Usage: "Fixed gas fee cap in wei (if set, overrides dynamic gas price)",
Value: 0,
EnvVar: prefixEnvVar("GAS_FEE_CAP"),
}

GasTipCapFlag = cli.Uint64Flag{
Name: "gas-tip-cap",
Usage: "Fixed gas tip cap in wei (if set, overrides dynamic gas tip)",
Value: 0,
EnvVar: prefixEnvVar("GAS_TIP_CAP"),
}
)

var requiredFlags = []cli.Flag{
Expand Down Expand Up @@ -210,6 +225,10 @@ var optionalFlags = []cli.Flag{
ExternalSignChainFlag,
ExternalSignUrlFlag,
ExternalSignRsaPrivFlag,

// Gas fee
GasFeeCapFlag,
GasTipCapFlag,
}

// Flags contains the list of configuration options available to the binary.
Expand Down