Skip to content

Commit

Permalink
Merge pull request #320 from bandprotocol/x-globalfee-params-v0.47
Browse files Browse the repository at this point in the history
create params for x/globalfee
  • Loading branch information
RogerKSI authored Sep 13, 2023
2 parents 0c782eb + dd2aa74 commit edc577f
Show file tree
Hide file tree
Showing 33 changed files with 1,400 additions and 448 deletions.
21 changes: 10 additions & 11 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"

"github.com/bandprotocol/chain/v2/x/globalfee/feechecker"
globalfeekeeper "github.com/bandprotocol/chain/v2/x/globalfee/keeper"
oraclekeeper "github.com/bandprotocol/chain/v2/x/oracle/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions
OracleKeeper *oraclekeeper.Keeper
IBCKeeper *ibckeeper.Keeper
GlobalFeeSubspace paramtypes.Subspace
StakingKeeper *stakingkeeper.Keeper
OracleKeeper *oraclekeeper.Keeper
IBCKeeper *ibckeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
GlobalfeeKeeper *globalfeekeeper.Keeper
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
Expand All @@ -39,20 +39,19 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.IBCKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "IBC keeper is required for AnteHandler")
}
if options.GlobalfeeKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "Globalfee keeper is required for AnteHandler")
}

sigGasConsumer := options.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
}

if options.TxFeeChecker == nil {
if options.GlobalFeeSubspace.Name() == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrNotFound, "globalfee param store is required for AnteHandler")
}

feeChecker := feechecker.NewFeeChecker(
options.OracleKeeper,
options.GlobalFeeSubspace,
options.GlobalfeeKeeper,
options.StakingKeeper,
)
options.TxFeeChecker = feeChecker.CheckTxFeeWithMinGasPrices
Expand Down
32 changes: 19 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"

owasm "github.com/bandprotocol/go-owasm/api"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
Expand All @@ -18,6 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
cosmosnodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -112,8 +113,6 @@ import (
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"

owasm "github.com/bandprotocol/go-owasm/api"

"github.com/bandprotocol/chain/v2/app/keepers"
"github.com/bandprotocol/chain/v2/app/upgrades"
"github.com/bandprotocol/chain/v2/app/upgrades/v2_6"
Expand All @@ -122,10 +121,11 @@ import (
bandbank "github.com/bandprotocol/chain/v2/x/bank"
bandbankkeeper "github.com/bandprotocol/chain/v2/x/bank/keeper"
"github.com/bandprotocol/chain/v2/x/globalfee"
globalfeekeeper "github.com/bandprotocol/chain/v2/x/globalfee/keeper"
globalfeetypes "github.com/bandprotocol/chain/v2/x/globalfee/types"
"github.com/bandprotocol/chain/v2/x/oracle"
oraclekeeper "github.com/bandprotocol/chain/v2/x/oracle/keeper"
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
cosmosnodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
)

const (
Expand Down Expand Up @@ -285,6 +285,7 @@ func NewBandApp(
icahosttypes.StoreKey,
group.StoreKey,
oracletypes.StoreKey,
globalfeetypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -526,6 +527,12 @@ func NewBandApp(
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

app.GlobalfeeKeeper = globalfeekeeper.NewKeeper(
appCodec,
keys[globalfeetypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

/**** Module Options ****/
// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
// we prefer to be more strict in what arguments the modules expect.
Expand Down Expand Up @@ -593,7 +600,7 @@ func NewBandApp(
transferModule,
icaModule,
oracleModule,
globalfee.NewAppModule(app.GetSubspace(globalfee.ModuleName)),
globalfee.NewAppModule(app.GlobalfeeKeeper),
)
// NOTE: Oracle module must occur before distr as it takes some fee to distribute to active oracle validators.
// NOTE: During begin block slashing happens after distr.BeginBlocker so that there is nothing left
Expand Down Expand Up @@ -623,7 +630,7 @@ func NewBandApp(
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
globalfee.ModuleName,
globalfeetypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName,
Expand All @@ -648,7 +655,7 @@ func NewBandApp(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
globalfee.ModuleName,
globalfeetypes.ModuleName,
)
// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
Expand Down Expand Up @@ -679,7 +686,7 @@ func NewBandApp(
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
oracletypes.ModuleName,
globalfee.ModuleName,
globalfeetypes.ModuleName,
)

app.mm.RegisterInvariants(app.CrisisKeeper)
Expand Down Expand Up @@ -721,10 +728,10 @@ func NewBandApp(
FeegrantKeeper: app.FeegrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
OracleKeeper: &app.OracleKeeper,
IBCKeeper: app.IBCKeeper,
GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName),
StakingKeeper: app.StakingKeeper,
OracleKeeper: &app.OracleKeeper,
IBCKeeper: app.IBCKeeper,
StakingKeeper: app.StakingKeeper,
GlobalfeeKeeper: &app.GlobalfeeKeeper,
},
)
if err != nil {
Expand Down Expand Up @@ -959,7 +966,6 @@ func initParamsKeeper(
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(oracletypes.ModuleName)
paramsKeeper.Subspace(globalfee.ModuleName)

return paramsKeeper
}
Expand Down
3 changes: 1 addition & 2 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"

"github.com/bandprotocol/chain/v2/app/upgrades/v2_6"
"github.com/bandprotocol/chain/v2/x/globalfee"
globalfeetypes "github.com/bandprotocol/chain/v2/x/globalfee/types"
"github.com/bandprotocol/chain/v2/x/oracle"
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
Expand Down Expand Up @@ -109,6 +108,6 @@ func NewDefaultGenesisState() GenesisState {
ibctransafertypes.ModuleName: ibctransfer.AppModuleBasic{}.DefaultGenesis(cdc),
icatypes.ModuleName: cdc.MustMarshalJSON(icaGenesis),
oracletypes.ModuleName: oracle.AppModuleBasic{}.DefaultGenesis(cdc),
globalfee.ModuleName: cdc.MustMarshalJSON(globalfeeGenesis),
globalfeetypes.ModuleName: cdc.MustMarshalJSON(globalfeeGenesis),
}
}
2 changes: 2 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keepers

import (
globalfeekeeper "github.com/bandprotocol/chain/v2/x/globalfee/keeper"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
Expand Down Expand Up @@ -47,6 +48,7 @@ type AppKeepers struct {
GroupKeeper groupkeeper.Keeper
OracleKeeper oraclekeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
GlobalfeeKeeper globalfeekeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down
9 changes: 5 additions & 4 deletions app/upgrades/v2_6/constants.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package v2_6

import (
"github.com/bandprotocol/chain/v2/app/upgrades"
"github.com/bandprotocol/chain/v2/x/globalfee"
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
Expand All @@ -15,6 +12,10 @@ import (
"github.com/cosmos/cosmos-sdk/x/group"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"

"github.com/bandprotocol/chain/v2/app/upgrades"
globalfeetypes "github.com/bandprotocol/chain/v2/x/globalfee/types"
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
)

const UpgradeName = "v2_6"
Expand All @@ -23,7 +24,7 @@ var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{
Added: []string{group.StoreKey, globalfee.ModuleName},
Added: []string{group.StoreKey, globalfeetypes.StoreKey},
},
}

Expand Down
19 changes: 10 additions & 9 deletions app/upgrades/v2_6/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package v2_6
import (
"github.com/bandprotocol/chain/v2/app/keepers"
"github.com/bandprotocol/chain/v2/app/upgrades"
"github.com/bandprotocol/chain/v2/x/globalfee"
globalfeetypes "github.com/bandprotocol/chain/v2/x/globalfee/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
Expand All @@ -26,16 +25,18 @@ func CreateUpgradeHandler(
}
keepers.ICAHostKeeper.SetParams(ctx, hostParams)

minGasPriceGenesisState := &globalfeetypes.GenesisState{
Params: globalfeetypes.Params{
MinimumGasPrices: sdk.DecCoins{sdk.NewDecCoinFromDec("uband", sdk.NewDecWithPrec(25, 4))},
},
vm, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
return nil, err
}
am.GetSubspace(globalfee.ModuleName).SetParamSet(ctx, &minGasPriceGenesisState.Params)

// set version of globalfee so that it won't run initgenesis again
fromVM["globalfee"] = 1
err = keepers.GlobalfeeKeeper.SetParams(ctx, globalfeetypes.Params{
MinimumGasPrices: sdk.DecCoins{sdk.NewDecCoinFromDec("uband", sdk.NewDecWithPrec(25, 4))},
})
if err != nil {
return nil, err
}

return mm.RunMigrations(ctx, configurator, fromVM)
return vm, nil
}
}
25 changes: 10 additions & 15 deletions proto/globalfee/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,23 @@ package globalfee.v1beta1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/v1beta1/coin.proto";
import "globalfee/v1beta1/genesis.proto";

option go_package = "github.com/bandprotocol/chain/v2/x/globalfee/types";

// Query defines the gRPC querier service.
service Query {
rpc MinimumGasPrices(QueryMinimumGasPricesRequest) returns (QueryMinimumGasPricesResponse) {
option (google.api.http).get = "/globalfee/v1beta1/minimum_gas_prices";
// Params queries parameters of globalfee module
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/globalfee/v1beta1/params";
}
}

// QueryMinimumGasPricesRequest is the request type for the
// Query/MinimumGasPrices RPC method.
message QueryMinimumGasPricesRequest {}
// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryMinimumGasPricesResponse is the response type for the
// Query/MinimumGasPrices RPC method.
message QueryMinimumGasPricesResponse {
repeated cosmos.base.v1beta1.DecCoin minimum_gas_prices = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "minimum_gas_prices,omitempty",
(gogoproto.moretags) = "yaml:\"minimum_gas_prices\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"
];
// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// pagination defines an optional pagination for the request.
Params params = 1 [(gogoproto.nullable) = false];
}
39 changes: 39 additions & 0 deletions proto/globalfee/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
syntax = "proto3";
package globalfee.v1beta1;

option go_package = "github.com/bandprotocol/chain/v2/x/globalfee/types";

import "cosmos/msg/v1/msg.proto";
import "globalfee/v1beta1/genesis.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";

// Msg defines the x/globalfee Msg service.
service Msg {
// UpdateParams defines a governance operation for updating the x/globalfee module
// parameters.
//
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/globalfee parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
9 changes: 0 additions & 9 deletions x/globalfee/alias.go

This file was deleted.

14 changes: 7 additions & 7 deletions x/globalfee/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ import (
func GetQueryCmd() *cobra.Command {
queryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the global fee module",
Short: "Querying commands for the globalfee module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
queryCmd.AddCommand(
GetCmdShowMinimumGasPrices(),
GetQueryCmdParams(),
)
return queryCmd
}

func GetCmdShowMinimumGasPrices() *cobra.Command {
func GetQueryCmdParams() *cobra.Command {
cmd := &cobra.Command{
Use: "minimum-gas-prices",
Short: "Show minimum gas prices",
Long: "Show all minimum gas prices",
Use: "params",
Short: "Show params",
Long: "Show parameter of globalfee module",
Aliases: []string{"min"},
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -36,7 +36,7 @@ func GetCmdShowMinimumGasPrices() *cobra.Command {
}

queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.MinimumGasPrices(cmd.Context(), &types.QueryMinimumGasPricesRequest{})
res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit edc577f

Please sign in to comment.