diff --git a/lib/contracts/feeoraclev2/deploy.go b/lib/contracts/feeoraclev2/deploy.go index 69fe098fb..2981d43c9 100644 --- a/lib/contracts/feeoraclev2/deploy.go +++ b/lib/contracts/feeoraclev2/deploy.go @@ -25,7 +25,7 @@ type DeploymentConfig struct { Owner common.Address Deployer common.Address Manager common.Address // manager is the address that can set fee parameters (gas price, conversion rates) - BaseGasLimit uint32 // must fit in uint24 (max: 16,777,215) + BaseGasLimit *big.Int // must fit in uint24 (max: 16,777,215) ProtocolFee *big.Int // must fit in uint72 (max: 4,722,366,482,869,645,213,695) } @@ -33,6 +33,7 @@ func isEmpty(addr common.Address) bool { return addr == common.Address{} } +var maxUint24 = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 24), big.NewInt(1)) var maxUint72 = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 72), big.NewInt(1)) func (cfg DeploymentConfig) Validate() error { @@ -57,7 +58,7 @@ func (cfg DeploymentConfig) Validate() error { if isEmpty(cfg.Manager) { return errors.New("manager is zero") } - if cfg.BaseGasLimit > (1<<24 - 1) { + if cfg.BaseGasLimit.Cmp(maxUint24) > 0 { return errors.New("base gas limit too high") } if cfg.ProtocolFee.Cmp(maxUint72) > 0 { @@ -125,7 +126,7 @@ func Deploy(ctx context.Context, network netconf.ID, chainID uint64, destChainID Owner: eoa.MustAddress(network, eoa.RoleManager), Deployer: eoa.MustAddress(network, eoa.RoleDeployer), Manager: eoa.MustAddress(network, eoa.RoleMonitor), // NOTE: monitor is owner of fee oracle contracts, because monitor manages on chain gas prices / conversion rates - BaseGasLimit: 100_000, + BaseGasLimit: big.NewInt(100_000), ProtocolFee: big.NewInt(0), } diff --git a/lib/contracts/feeoraclev2/feeparams.go b/lib/contracts/feeoraclev2/feeparams.go index 7b838f160..626f6cb8e 100644 --- a/lib/contracts/feeoraclev2/feeparams.go +++ b/lib/contracts/feeoraclev2/feeparams.go @@ -32,10 +32,7 @@ func feeParams(ctx context.Context, srcChainID uint64, destChainIDs []uint64, ba return nil, errors.New("meta by chain id", "dest_chain", destChain.Name) } - ps, err := destFeeParams(ctx, srcChain, destChain, backends, pricer) - if err != nil { - return nil, err - } + ps := destFeeParams(ctx, srcChain, destChain, backends, pricer) resp = append(resp, ps) } @@ -45,7 +42,7 @@ func feeParams(ctx context.Context, srcChainID uint64, destChainIDs []uint64, ba // feeParams returns the fee parameters for the given source token and destination chains. func destFeeParams(ctx context.Context, srcChain evmchain.Metadata, destChain evmchain.Metadata, backends ethbackend.Backends, pricer tokens.Pricer, -) (bindings.IFeeOracleV2FeeParams, error) { +) bindings.IFeeOracleV2FeeParams { // conversion rate from "dest token" to "src token" // ex if dest chain is ETH, and src chain is OMNI, we need to know the rate of ETH to OMNI. toNativeRate, err := conversionRate(ctx, pricer, destChain.NativeToken, srcChain.NativeToken) @@ -54,26 +51,34 @@ func destFeeParams(ctx context.Context, srcChain evmchain.Metadata, destChain ev toNativeRate = 1 } - localBackend, err := backends.Backend(destChain.ChainID) + // Get execution gas price, defaulting to 1 Gwei if any error occurs. + var execBackend *ethbackend.Backend + var execGasPrice *big.Int + execBackend, err = backends.Backend(destChain.ChainID) if err != nil { - return bindings.IFeeOracleV2FeeParams{}, errors.Wrap(err, "get local backend", "dest_chain", destChain.Name) - } - - remoteBackend, err := backends.Backend(destChain.PostsTo) - if err != nil { - return bindings.IFeeOracleV2FeeParams{}, errors.Wrap(err, "get remote backend", "dest_chain", destChain.Name) - } - - execGasPrice, err := localBackend.SuggestGasPrice(ctx) - if err != nil { - log.Warn(ctx, "Failed fetching exec gas price, using default 1 Gwei", err, "dest_chain", destChain.Name) + log.Warn(ctx, "Failed getting exec backend, using default 1 Gwei", err, "dest_chain", destChain.Name) execGasPrice = big.NewInt(params.GWei) + } else { + execGasPrice, err = execBackend.SuggestGasPrice(ctx) + if err != nil { + log.Warn(ctx, "Failed fetching exec gas price, using default 1 Gwei", err, "dest_chain", destChain.Name) + execGasPrice = big.NewInt(params.GWei) + } } - dataGasPrice, err := remoteBackend.SuggestGasPrice(ctx) + // Get data gas price, defaulting to 1 Gwei if any error occurs. + var dataBackend *ethbackend.Backend + var dataGasPrice *big.Int + dataBackend, err = backends.Backend(destChain.PostsTo) if err != nil { - log.Warn(ctx, "Failed fetching data gas price, using default 1 Gwei", err, "dest_chain", destChain.Name) + log.Warn(ctx, "Failed getting data backend, using default 1 Gwei", err, "dest_chain", destChain.Name) dataGasPrice = big.NewInt(params.GWei) + } else { + dataGasPrice, err = dataBackend.SuggestGasPrice(ctx) + if err != nil { + log.Warn(ctx, "Failed fetching data gas price, using default 1 Gwei", err, "dest_chain", destChain.Name) + dataGasPrice = big.NewInt(params.GWei) + } } return bindings.IFeeOracleV2FeeParams{ @@ -81,7 +86,7 @@ func destFeeParams(ctx context.Context, srcChain evmchain.Metadata, destChain ev ExecGasPrice: gasprice.Tier(execGasPrice.Uint64()), DataGasPrice: gasprice.Tier(dataGasPrice.Uint64()), ToNativeRate: rateToNumerator(toNativeRate), - }, nil + } } // conversionRate returns the conversion rate C from token F to token T, where C = price(F) / price(T).