Skip to content

Commit

Permalink
feat: add gas adjustment (#26)
Browse files Browse the repository at this point in the history
* feat: remove unwanted log

* feat: add missing env e.g.
danidomi authored Feb 1, 2025
1 parent 017dfc1 commit c3d5374
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ ORACLE_COSMOS_GRPC="tcp://localhost:9900"
ORACLE_COSMOS_STREAM_GRPC="tcp://localhost:9999"
ORACLE_TENDERMINT_RPC="http://localhost:26657"
ORACLE_COSMOS_GAS_PRICES="500000000inj"
ORACLE_COSMOS_GAS_ADJUST=1.5
ORACLE_NETWORK_NODE=mainnet,lb

ORACLE_COSMOS_KEYRING="file"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -81,6 +81,7 @@ services:
ORACLE_COSMOS_STREAM_GRPC: tcp://sentry0.injective.network:9999
ORACLE_TENDERMINT_RPC: http://sentry0.injective.network:26657
ORACLE_COSMOS_GAS_PRICES: 500000000inj
ORACLE_COSMOS_GAS_ADJUST: 1.5
# keyring config
ORACLE_COSMOS_KEYRING: file
ORACLE_COSMOS_KEYRING_DIR: /root/keyring-oracle
8 changes: 8 additions & 0 deletions cmd/injective-price-oracle/options.go
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ func initCosmosOptions(
cosmosStreamGRPC **string,
tendermintRPC **string,
cosmosGasPrices **string,
cosmosGasAdjust **float64,
networkNode **string,
) {
*cosmosChainID = cmd.String(cli.StringOpt{
@@ -75,6 +76,13 @@ func initCosmosOptions(
Value: "", // example: 500000000inj
})

*cosmosGasAdjust = cmd.Float64(cli.Float64Opt{
Name: "cosmos-gas-adjust",
Desc: "Specify Cosmos chain transaction fees gas adjustment factor",
EnvVar: "ORACLE_COSMOS_GAS_ADJUST",
Value: 1.5,
})

*networkNode = cmd.String(cli.StringOpt{
Name: "cosmos-network-node",
Desc: "Specify network and node (e.g mainnet,lb)",
11 changes: 8 additions & 3 deletions cmd/injective-price-oracle/oracle.go
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ func oracleCmd(cmd *cli.Cmd) {
cosmosStreamGRPC *string
tendermintRPC *string
cosmosGasPrices *string
cosmosGasAdjust *float64
networkNode *string

// Cosmos Key Management
@@ -71,6 +72,7 @@ func oracleCmd(cmd *cli.Cmd) {
&cosmosStreamGRPC,
&tendermintRPC,
&cosmosGasPrices,
&cosmosGasAdjust,
&networkNode,
)

@@ -153,7 +155,6 @@ func oracleCmd(cmd *cli.Cmd) {
network.TmEndpoint = *tendermintRPC
}

clientCtx = clientCtx.WithNodeURI(network.TmEndpoint)
tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
log.WithError(err).Fatalln("failed to connect to tendermint RPC")
@@ -166,8 +167,12 @@ func oracleCmd(cmd *cli.Cmd) {
network.ChainStreamGrpcEndpoint = *cosmosStreamGRPC // env var
}

clientCtx = clientCtx.WithClient(tmRPC)
cosmosClient, err := chainclient.NewChainClient(clientCtx, network, common.OptionGasPrices(*cosmosGasPrices))
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmRPC)
txFactory := chainclient.NewTxFactory(clientCtx)
txFactory = txFactory.WithGasAdjustment(*cosmosGasAdjust)
txFactory = txFactory.WithGasPrices(*cosmosGasPrices)

cosmosClient, err := chainclient.NewChainClient(clientCtx, network, common.OptionTxFactory(&txFactory))
if err != nil {
log.WithError(err).WithFields(log.Fields{
"endpoint": network.ChainGrpcEndpoint,

0 comments on commit c3d5374

Please sign in to comment.