mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
f37321839b
* add `x/kavamint` module (#1376) * stub out the x/kavamint module * mint staking rewards in x/kavamint BeginBlocker * calculate cumulative inflation from x/kavamint * cleanup, abstract bond denom, grpc query tests * store & use previous block time to calculate mints * move test suite to testutil * add test of x/kavamint BeginBlocker * cleanup & comments from @DracoLi review * fix x/incentive integration test * remove rest client grpc test * add x/kavamint module spec * track previous block time in genesis * suggested cleanup from PR review * bugfix incorrect module account check * add x/community module (#1388) * add x/community module * refactor and setup fund-community-pool tx * remove unused features (params, genesis state) * test x/community query and message * update with master branch deps * updates from review * indicate deprecated methods on module (still needed to fulfill interface) * remove legacy querier * derive msg Route() and Type() from sdk.MsgTypeURL(&msg) * use module name for message Route() * mint community pool inflation in x/kavamint (#1389) * mint community pool inflation in x/kavamint * refactor x/kavamint abci inflation test * test inflation from x/kavamint * default kavamint rates to 0% * rename kavamint account name variables * panic if genesis kavamint previous block time not set * emit event on kavamint begin blocker * add kavamint year of inflation sanity check test * update fund_community_pool message event * add x/community spec * refactor inflation accumulation into single func * use new comm pool in kavadist multispend proposal (#1403) the x/community module houses the new community pool. this commit points the CommunityPoolMultiSpendProposal at the new community pool so that multispend proposals can continue to be processed once original fee pool funds are move to x/community * updates from proto lint changes * update earn proposals to use new community pool originally the CommunityPoolDepositProposal & CommunityPoolWithdrawProposal used the vanilla community pool fee pool. this commit updates them both to use the new x/community module account. * spec formatting update * add x/community & x/kavamint to internal testnet genesis * increase test coverage of x/kavamint * increase test coverage of x/community * use string type for sdk.Dec proto fields; disable generation of getters for genesis and params (and other store objects) * follow sdk conventions for params endpoint naming * add kavamint to swagger; update swagger & proto docs * remove legacy querier; touch up module to match others * reduce max minting rate; refactor genesis to allow nil/zero block time; repace proto stringers and remove getters; keep sdk.Dec values strings in protos; increase validation of sdk.Dec values in params; increase coverage; add module account permission checks; ensure import and export of genesis does not change state * fix scaling of rate values -- should be yearly rates * revert key change * fix typo in test name * fix regression in running tests -- rename method Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
153 lines
5.0 KiB
Go
153 lines
5.0 KiB
Go
package kavamint
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
"github.com/spf13/cobra"
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
"github.com/kava-labs/kava/x/kavamint/client/cli"
|
|
"github.com/kava-labs/kava/x/kavamint/keeper"
|
|
"github.com/kava-labs/kava/x/kavamint/types"
|
|
)
|
|
|
|
var (
|
|
_ module.AppModule = AppModule{}
|
|
_ module.AppModuleBasic = AppModuleBasic{}
|
|
)
|
|
|
|
// AppModuleBasic defines the basic application module used by the kavamint module.
|
|
type AppModuleBasic struct {
|
|
cdc codec.Codec
|
|
}
|
|
|
|
var _ module.AppModuleBasic = AppModuleBasic{}
|
|
|
|
// Name returns the mint module's name.
|
|
func (AppModuleBasic) Name() string {
|
|
return types.ModuleName
|
|
}
|
|
|
|
// RegisterLegacyAminoCodec registers the kavamint module's types on the given LegacyAmino codec.
|
|
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}
|
|
|
|
// RegisterInterfaces registers the module's interface types
|
|
func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {}
|
|
|
|
// DefaultGenesis returns default genesis state as raw bytes for the mint
|
|
// module.
|
|
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
|
|
return cdc.MustMarshalJSON(types.DefaultGenesisState())
|
|
}
|
|
|
|
// ValidateGenesis performs genesis state validation for the kavamint module.
|
|
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
|
|
var gs types.GenesisState
|
|
if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
|
|
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
|
|
}
|
|
|
|
return gs.Validate()
|
|
}
|
|
|
|
// RegisterRESTRoutes registers the REST routes for the kavamint module.
|
|
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {}
|
|
|
|
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the kavamint module.
|
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
|
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
|
|
|
}
|
|
|
|
// GetTxCmd returns no root tx command for the kavamint module.
|
|
func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }
|
|
|
|
// GetQueryCmd returns the root query command for the kavamint module.
|
|
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
|
return cli.GetQueryCmd()
|
|
}
|
|
|
|
// AppModule implements an application module for the kavamint module.
|
|
type AppModule struct {
|
|
AppModuleBasic
|
|
|
|
keeper keeper.Keeper
|
|
authKeeper types.AccountKeeper
|
|
}
|
|
|
|
// NewAppModule creates a new AppModule object
|
|
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper) AppModule {
|
|
return AppModule{
|
|
AppModuleBasic: AppModuleBasic{cdc: cdc},
|
|
keeper: keeper,
|
|
authKeeper: ak,
|
|
}
|
|
}
|
|
|
|
// Name returns the kavamint module's name.
|
|
func (AppModule) Name() string {
|
|
return types.ModuleName
|
|
}
|
|
|
|
// RegisterInvariants registers the kavamint module invariants.
|
|
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
|
|
|
|
// Route returns the message routing key for the kavamint module.
|
|
func (AppModule) Route() sdk.Route { return sdk.Route{} }
|
|
|
|
// QuerierRoute returns the kavamint module's querier route name.
|
|
func (AppModule) QuerierRoute() string {
|
|
return types.QuerierRoute
|
|
}
|
|
|
|
// LegacyQuerierHandler returns the kavamint module sdk.Querier.
|
|
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
|
return nil
|
|
}
|
|
|
|
// RegisterServices registers a gRPC query service to respond to the
|
|
// module-specific gRPC queries.
|
|
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
|
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
|
|
}
|
|
|
|
// InitGenesis performs genesis initialization for the kavamint module. It returns
|
|
// no validator updates.
|
|
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
|
|
var genesisState types.GenesisState
|
|
cdc.MustUnmarshalJSON(data, &genesisState)
|
|
|
|
InitGenesis(ctx, am.keeper, am.authKeeper, &genesisState)
|
|
return []abci.ValidatorUpdate{}
|
|
}
|
|
|
|
// ExportGenesis returns the exported genesis state as raw bytes for the mint
|
|
// module.
|
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
|
gs := ExportGenesis(ctx, am.keeper)
|
|
return cdc.MustMarshalJSON(gs)
|
|
}
|
|
|
|
// ConsensusVersion implements AppModule/ConsensusVersion.
|
|
func (AppModule) ConsensusVersion() uint64 { return 1 }
|
|
|
|
// BeginBlock returns the begin blocker for the kavamint module.
|
|
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
|
|
BeginBlocker(ctx, am.keeper)
|
|
}
|
|
|
|
// EndBlock returns the end blocker for the kavamint module. It returns no validator
|
|
// updates.
|
|
func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
|
|
return []abci.ValidatorUpdate{}
|
|
}
|