Skip to content

Commit

Permalink
feat: upgraded the app with treasury module to SDK v0.50
Browse files Browse the repository at this point in the history
  • Loading branch information
vishal-kanna committed Dec 14, 2023
1 parent 8a60bd6 commit 7b5f1ab
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 118 deletions.
72 changes: 36 additions & 36 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ import (
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"

ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
palomamempool "github.com/palomachain/paloma/app/mempool"
appparams "github.com/palomachain/paloma/app/params"

// xchain "github.com/palomachain/paloma/internal/x-chain"
// consensusmodule "github.com/palomachain/paloma/x/consensus"
Expand All @@ -143,10 +144,10 @@ import (
// schedulermodule "github.com/palomachain/paloma/x/scheduler"
// schedulermodulekeeper "github.com/palomachain/paloma/x/scheduler/keeper"
// schedulermoduletypes "github.com/palomachain/paloma/x/scheduler/types"
// treasurymodule "github.com/palomachain/paloma/x/treasury"
// treasuryclient "github.com/palomachain/paloma/x/treasury/client"
// treasurymodulekeeper "github.com/palomachain/paloma/x/treasury/keeper"
// treasurymoduletypes "github.com/palomachain/paloma/x/treasury/types"
treasurymodule "github.com/palomachain/paloma/x/treasury"
treasuryclient "github.com/palomachain/paloma/x/treasury/client"
treasurymodulekeeper "github.com/palomachain/paloma/x/treasury/keeper"
treasurymoduletypes "github.com/palomachain/paloma/x/treasury/types"

// valsetmodule "github.com/palomachain/paloma/x/valset"
// valsetmodulekeeper "github.com/palomachain/paloma/x/valset/keeper"
Expand All @@ -166,6 +167,9 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
return []govclient.ProposalHandler{
paramsclient.ProposalHandler,
evmclient.ProposalHandler,
// gravityclient.ProposalHandler,
//ibcclientclient has been removed ,because it is deprecated
treasuryclient.ProposalHandler,
}
}

Expand All @@ -181,10 +185,12 @@ var (
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
// gravitymoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: nil,
icatypes.ModuleName: nil,
evmmoduletypes.ModuleName: {authtypes.Burner, authtypes.Minter},
wasmtypes.ModuleName: {authtypes.Burner},
treasurymoduletypes.ModuleName: {authtypes.Burner, authtypes.Minter},
}
)

Expand Down Expand Up @@ -247,8 +253,8 @@ type App struct {
// ConsensusKeeper consensusmodulekeeper.Keeper
// ValsetKeeper valsetmodulekeeper.Keeper
// PalomaKeeper palomamodulekeeper.Keeper
// TreasuryKeeper treasurymodulekeeper.Keeper
EvmKeeper evmmodulekeeper.Keeper
TreasuryKeeper treasurymodulekeeper.Keeper
EvmKeeper evmmodulekeeper.Keeper
// GravityKeeper gravitymodulekeeper.Keeper
wasmKeeper wasmkeeper.Keeper

Expand All @@ -268,7 +274,6 @@ func New(
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
encodingCfg appparams.EncodingConfig,
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
Expand Down Expand Up @@ -324,11 +329,9 @@ func New(
// schedulermoduletypes.StoreKey,
// consensusmoduletypes.StoreKey,
// valsetmoduletypes.StoreKey,
// treasurymoduletypes.StoreKey,
// // wasm.StoreKey,
evmmoduletypes.StoreKey,
treasurymoduletypes.StoreKey,
wasmtypes.StoreKey,
// evmmoduletypes.StoreKey,
evmmoduletypes.StoreKey,
// gravitymoduletypes.StoreKey,
// consensusparamtypes.StoreKey,
crisistypes.StoreKey,
Expand All @@ -340,7 +343,7 @@ func New(
// consensusmoduletypes.MemStoreKey,
evmmoduletypes.MemStoreKey,
// schedulermoduletypes.MemStoreKey,
// treasurymoduletypes.MemStoreKey,
treasurymoduletypes.MemStoreKey,
// palomamoduletypes.MemStoreKey,
)

Expand Down Expand Up @@ -610,23 +613,25 @@ func New(
// },
// )

// app.TreasuryKeeper = *treasurymodulekeeper.NewKeeper(
// appCodec,
// keys[treasurymoduletypes.StoreKey],
// memKeys[treasurymoduletypes.MemStoreKey],
// app.GetSubspace("" /*schedulermoduletypes.ModuleName*/),
// app.BankKeeper,
// app.AccountKeeper,
// nil, // app.SchedulerKeeper,
// )
app.TreasuryKeeper = *treasurymodulekeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[treasurymoduletypes.StoreKey]),
app.GetSubspace("" /*schedulermoduletypes.ModuleName*/),
app.BankKeeper,
app.AccountKeeper,
nil, // app.SchedulerKeeper,
)

// app.ScopedConsensusKeeper = scopedConsensusKeeper

govRouter := govv1beta1.NewRouter()
govRouter.
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(evmmoduletypes.RouterKey, evm.NewReferenceChainReferenceIDProposalHandler(app.EvmKeeper))
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(evmmoduletypes.RouterKey, evm.NewReferenceChainReferenceIDProposalHandler(app.EvmKeeper)).
// AddRoute(gravitymoduletypes.RouterKey, gravitymodulekeeper.NewGravityProposalHandler(app.GravityKeeper)).
AddRoute(treasurymoduletypes.RouterKey, treasurymodule.NewFeeProposalHandler(app.TreasuryKeeper))

// Example of setting gov params:
govKeeper := govkeeper.NewKeeper(
Expand Down Expand Up @@ -740,7 +745,7 @@ func New(
// schedulerModule := schedulermodule.NewAppModule(appCodec, app.SchedulerKeeper, app.AccountKeeper, app.BankKeeper)
// palomaModule := palomamodule.NewAppModule(appCodec, app.PalomaKeeper, app.AccountKeeper, app.BankKeeper)
// gravityModule := gravitymodule.NewAppModule(appCodec, app.GravityKeeper, app.BankKeeper)
// treasuryModule := treasurymodule.NewAppModule(appCodec, app.TreasuryKeeper, app.AccountKeeper, app.BankKeeper)
treasuryModule := treasurymodule.NewAppModule(appCodec, app.TreasuryKeeper, app.AccountKeeper, app.BankKeeper)
app.ModuleManager = module.NewManager(
genutil.NewAppModule(
app.AccountKeeper,
Expand Down Expand Up @@ -768,7 +773,7 @@ func New(
evmModule,
// gravityModule,
// palomaModule,
// treasuryModule,
treasuryModule,
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasm.ModuleName)),
ibc.NewAppModule(app.IBCKeeper),
transfer.NewAppModule(app.TransferKeeper),
Expand All @@ -787,6 +792,7 @@ func New(
},
),
})

app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino)
app.BasicModuleManager.RegisterInterfaces(interfaceRegistry)
// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -813,12 +819,10 @@ func New(
genutiltypes.ModuleName,
// valsetmoduletypes.ModuleName,
// palomamoduletypes.ModuleName,
// wasm.ModuleName,
evmmoduletypes.ModuleName,
wasmtypes.ModuleName,
// evmmoduletypes.ModuleName,
// gravitymoduletypes.ModuleName,
// treasurymoduletypes.ModuleName,
treasurymoduletypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
icatypes.ModuleName,
Expand Down Expand Up @@ -847,16 +851,14 @@ func New(
genutiltypes.ModuleName,
// valsetmoduletypes.ModuleName,
// palomamoduletypes.ModuleName,
// wasm.ModuleName,
evmmoduletypes.ModuleName,
wasmtypes.ModuleName,
// evmmoduletypes.ModuleName,
// gravitymoduletypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// treasurymoduletypes.ModuleName,
treasurymoduletypes.ModuleName,
consensusparamtypes.ModuleName,
)

Expand Down Expand Up @@ -890,12 +892,10 @@ func New(
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// wasm.ModuleName,
evmmoduletypes.ModuleName,
wasmtypes.ModuleName,
// evmmoduletypes.ModuleName,
// gravitymoduletypes.ModuleName,
// treasurymoduletypes.ModuleName,
treasurymoduletypes.ModuleName,
consensusparamtypes.ModuleName,
)

Expand Down Expand Up @@ -1142,7 +1142,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
// paramsKeeper.Subspace(consensusmoduletypes.ModuleName)
// paramsKeeper.Subspace(valsetmoduletypes.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)
// paramsKeeper.Subspace(evmmoduletypes.ModuleName)
paramsKeeper.Subspace(evmmoduletypes.ModuleName)
// paramsKeeper.Subspace(gravitymoduletypes.ModuleName)

return paramsKeeper
Expand Down
4 changes: 1 addition & 3 deletions proto/palomachain/paloma/treasury/params.proto
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
syntax = "proto3";
package palomachain.paloma.treasury;

import "gogoproto/gogo.proto";

option go_package = "github.com/palomachain/paloma/x/treasury/types";

// Params defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;
message Params {
}
19 changes: 12 additions & 7 deletions x/treasury/genesis.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
package treasury

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/palomachain/paloma/x/treasury/keeper"
"github.com/palomachain/paloma/x/treasury/types"
)

// InitGenesis initializes the capability module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
k.SetParams(ctx, genState.Params)
func InitGenesis(ctx context.Context, k keeper.Keeper, genState types.GenesisState) {
sdkctx := sdk.UnwrapSDKContext(ctx)
k.SetParams(sdkctx, genState.Params)

err := k.SetCommunityFundFee(ctx, "0.01")
err := k.SetCommunityFundFee(sdkctx, "0.01")
if err != nil {
panic(err)
}

err = k.SetSecurityFee(ctx, "0.01")
err = k.SetSecurityFee(sdkctx, "0.01")
if err != nil {
panic(err)
}
}

// ExportGenesis returns the capability module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
func ExportGenesis(ctx context.Context, k keeper.Keeper) *types.GenesisState {
sdkctx := sdk.UnwrapSDKContext(ctx)

genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)
genesis.Params = k.GetParams(sdkctx)

fees, err := k.GetFees(ctx)
fees, err := k.GetFees(sdkctx)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/treasury/keeper/grpc_query_fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
"testing"

"github.com/cometbft/cometbft/libs/log"
"cosmossdk.io/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
keeperutilmocks "github.com/palomachain/paloma/util/keeper/mocks"
Expand Down
23 changes: 11 additions & 12 deletions x/treasury/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package keeper

import (
"context"
"errors"
"fmt"

"github.com/cometbft/cometbft/libs/log"
cosmosstore "cosmossdk.io/core/store"
"cosmossdk.io/log"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
xchain "github.com/palomachain/paloma/internal/x-chain"
Expand All @@ -18,7 +19,6 @@ const storeKey = "treasury"

type Keeper struct {
cdc codec.BinaryCodec
memKey storetypes.StoreKey
paramstore paramtypes.Subspace
bank types.BankKeeper
account types.AccountKeeper
Expand All @@ -30,8 +30,7 @@ type Keeper struct {

func NewKeeper(
cdc codec.BinaryCodec,
storeKey,
memKey storetypes.StoreKey,
storeKey cosmosstore.KVStoreService,
ps paramtypes.Subspace,
bank types.BankKeeper,
account types.AccountKeeper,
Expand All @@ -44,7 +43,6 @@ func NewKeeper(

return &Keeper{
cdc: cdc,
memKey: memKey,
paramstore: ps,
bank: bank,
account: account,
Expand All @@ -58,11 +56,12 @@ func NewKeeper(

func (k Keeper) ModuleName() string { return types.ModuleName }

func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
func (k Keeper) Logger(ctx context.Context) log.Logger {
sdkCtx := sdk.UnwrapSDKContext(ctx)
return sdkCtx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}

func (k Keeper) SetCommunityFundFee(ctx sdk.Context, fee string) error {
func (k Keeper) SetCommunityFundFee(ctx context.Context, fee string) error {
fees, err := k.GetFees(ctx)
if err != nil {
return err
Expand All @@ -75,7 +74,7 @@ func (k Keeper) SetCommunityFundFee(ctx sdk.Context, fee string) error {
return err
}

func (k Keeper) SetSecurityFee(ctx sdk.Context, fee string) error {
func (k Keeper) SetSecurityFee(ctx context.Context, fee string) error {
fees, err := k.GetFees(ctx)
if err != nil {
return err
Expand All @@ -88,7 +87,7 @@ func (k Keeper) SetSecurityFee(ctx sdk.Context, fee string) error {
return err
}

func (k Keeper) GetFees(ctx sdk.Context) (*types.Fees, error) {
func (k Keeper) GetFees(ctx context.Context) (*types.Fees, error) {
res, err := k.KeeperUtil.Load(k.Store.TreasuryStore(ctx), k.cdc, []byte(storeKey))
if errors.Is(err, keeperutil.ErrNotFound) {
return &types.Fees{}, nil
Expand All @@ -99,6 +98,6 @@ func (k Keeper) GetFees(ctx sdk.Context) (*types.Fees, error) {
return res, nil
}

func (k Keeper) setFees(ctx sdk.Context, fees *types.Fees) error {
func (k Keeper) setFees(ctx context.Context, fees *types.Fees) error {
return k.KeeperUtil.Save(k.Store.TreasuryStore(ctx), k.cdc, []byte(storeKey), fees)
}
2 changes: 1 addition & 1 deletion x/treasury/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"testing"

"github.com/cometbft/cometbft/libs/log"
"cosmossdk.io/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
keeperutil "github.com/palomachain/paloma/util/keeper"
Expand Down
Loading

0 comments on commit 7b5f1ab

Please sign in to comment.