Skip to content

Commit

Permalink
fix: fetch gas-prices from the chain config if provided
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Oct 12, 2024
1 parent 4e4e953 commit 41fa361
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cregistry/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/rand"
"net/http"
"net/url"
"strconv"
"time"

"github.com/cosmos/relayer/v2/relayer/chains/cosmos"
Expand Down Expand Up @@ -87,6 +88,12 @@ type ChainInfo struct {
MaxGasAmount uint64 `json:"max_gas_amount"`
ExtraCodecs []string `json:"extra_codecs"`
ExtensionOptions []provider.ExtensionOption `json:"extension_options"`
Fees struct {
FeeTokens []struct {
Denom string `json:"denom"`
LowGasPrice float64 `json:"low_gas_price"`
} `json:"fee_tokens"`
} `json:"fees"`
}

// NewChainInfo returns a ChainInfo that is uninitialized other than the provided zap.Logger.
Expand Down Expand Up @@ -292,14 +299,18 @@ func (c ChainInfo) GetChainConfig(ctx context.Context, forceAdd, testnet bool, n
debug := viper.GetBool("debug")
home := viper.GetString("home")

assetList, err := c.GetAssetList(ctx, testnet, name)
if err != nil {
return nil, err
}

var gasPrices string
if len(assetList.Assets) > 0 {
gasPrices = fmt.Sprintf("%.2f%s", 0.01, assetList.Assets[0].Base)
if len(c.Fees.FeeTokens) > 0 {
gasPrices = strconv.FormatFloat(c.Fees.FeeTokens[0].LowGasPrice, 'f', -1, 64) + c.Fees.FeeTokens[0].Denom
} else {
assetList, err := c.GetAssetList(ctx, testnet, name)
if err != nil {
return nil, err
}

if len(assetList.Assets) > 0 {
gasPrices = fmt.Sprintf("%.2f%s", 0.01, assetList.Assets[0].Base)
}
}

rpc, err := c.GetRandomRPCEndpoint(ctx, forceAdd)
Expand Down

0 comments on commit 41fa361

Please sign in to comment.