Skip to content

Commit

Permalink
create params for x/globalfee
Browse files Browse the repository at this point in the history
  • Loading branch information
colmazia committed Aug 15, 2023
1 parent 8912759 commit 3fb7dc2
Show file tree
Hide file tree
Showing 25 changed files with 1,507 additions and 554 deletions.
7 changes: 6 additions & 1 deletion app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
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"
)
Expand All @@ -22,6 +23,7 @@ type HandlerOptions struct {
GlobalFeeSubspace paramtypes.Subspace
StakingSubspace paramtypes.Subspace // 0.47 TODO: delete this line
StakingKeeper *stakingkeeper.Keeper
GlobalfeeKeeper *globalfeekeeper.Keeper
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
Expand All @@ -40,6 +42,9 @@ 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 {
Expand All @@ -53,7 +58,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {

feeChecker := feechecker.NewFeeChecker(
options.OracleKeeper,
options.GlobalFeeSubspace,
options.GlobalfeeKeeper,
options.StakingKeeper,
)
options.TxFeeChecker = feeChecker.CheckTxFeeWithMinGasPrices
Expand Down
13 changes: 12 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ 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"
Expand Down Expand Up @@ -284,6 +286,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 @@ -537,6 +540,13 @@ 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],
// 0.47 TODO: change to tech council address
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 @@ -605,7 +615,7 @@ func NewBandApp(
transferModule,
icaModule,
oracleModule,
globalfee.NewAppModule(app.GetSubspace(globalfee.ModuleName)),
globalfee.NewAppModule(app.GlobalfeeKeeper, app.GetSubspace(globalfee.ModuleName)),
)
// 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 @@ -738,6 +748,7 @@ func NewBandApp(
GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName),
StakingSubspace: app.GetSubspace(stakingtypes.ModuleName), // 0.47 TODO: delete this line
StakingKeeper: app.StakingKeeper,
GlobalfeeKeeper: &app.GlobalfeeKeeper,
},
)
if err != nil {
Expand Down
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
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 {}
18 changes: 18 additions & 0 deletions x/globalfee/exported/exported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package exported

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

type (
ParamSet = paramtypes.ParamSet

// Subspace defines an interface that implements the legacy x/params Subspace
// type.
//
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
GetParamSet(ctx sdk.Context, ps ParamSet)
}
)
26 changes: 9 additions & 17 deletions x/globalfee/feechecker/feechecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,28 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/authz"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

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

type FeeChecker struct {
OracleKeeper *oraclekeeper.Keeper
GlobalMinFee globalfee.ParamSource
StakingKeeper *stakingkeeper.Keeper
OracleKeeper *oraclekeeper.Keeper
GlobalfeeKeeper *keeper.Keeper
StakingKeeper *stakingkeeper.Keeper
}

func NewFeeChecker(
oracleKeeper *oraclekeeper.Keeper,
globalfeeSubspace paramtypes.Subspace,
globalfeeKeeper *keeper.Keeper,
stakingKeeper *stakingkeeper.Keeper,
) FeeChecker {
if !globalfeeSubspace.HasKeyTable() {
panic("global fee paramspace was not set up via module")
}

return FeeChecker{
OracleKeeper: oracleKeeper,
GlobalMinFee: globalfeeSubspace,
StakingKeeper: stakingKeeper,
OracleKeeper: oracleKeeper,
GlobalfeeKeeper: globalfeeKeeper,
StakingKeeper: stakingKeeper,
}
}

Expand Down Expand Up @@ -117,9 +111,7 @@ func (fc FeeChecker) GetGlobalMinGasPrices(ctx sdk.Context) (sdk.DecCoins, error
err error
)

if fc.GlobalMinFee.Has(ctx, types.ParamStoreKeyMinGasPrices) {
fc.GlobalMinFee.Get(ctx, types.ParamStoreKeyMinGasPrices, &globalMinGasPrices)
}
globalMinGasPrices = fc.GlobalfeeKeeper.GetParams(ctx).MinimumGasPrices
// global fee is empty set, set global fee to 0uband (bondDenom)
if len(globalMinGasPrices) == 0 {
globalMinGasPrices, err = fc.DefaultZeroGlobalFee(ctx)
Expand Down
Loading

0 comments on commit 3fb7dc2

Please sign in to comment.