Skip to content

Commit

Permalink
params migration
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsingh33 committed Dec 15, 2023
1 parent 44678fc commit b23ba4b
Show file tree
Hide file tree
Showing 22 changed files with 1,535 additions and 114 deletions.
28 changes: 16 additions & 12 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ func New(
// Subspace(baseapp.Paramspace).
// WithKeyTable(paramskeeper.ConsensusParamsKeyTable()),
// )
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())
govModAddress := authtypes.NewModuleAddress(govtypes.ModuleName).String()
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], govModAddress)
baseApp.SetParamStore(&app.ConsensusParamsKeeper)

// add capability keeper and ScopeToModule for ibc module
Expand Down Expand Up @@ -534,21 +535,21 @@ func New(
authtypes.ProtoBaseAccount,
app.ModuleAccountsPermissions(),
AccountAddressPrefix,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
app.cdc,
app.keys[banktypes.StoreKey],
app.AccountKeeper,
nil,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)
stakingKeeper := stakingkeeper.NewKeeper(
app.cdc,
app.keys[stakingtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)
app.MintKeeper = mintkeeper.NewKeeper(
app.cdc,
Expand All @@ -557,7 +558,7 @@ func New(
app.AccountKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)
app.DistrKeeper = distrkeeper.NewKeeper(
app.cdc,
Expand All @@ -566,22 +567,22 @@ func New(
app.BankKeeper,
stakingKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)
app.SlashingKeeper = slashingkeeper.NewKeeper(
app.cdc,
encoding.Amino,
app.keys[slashingtypes.StoreKey],
stakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)
app.CrisisKeeper = crisiskeeper.NewKeeper(
app.cdc,
app.keys[crisistypes.StoreKey],
invCheckPeriod,
app.BankKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)

app.AuthzKeeper = authzkeeper.NewKeeper(
Expand All @@ -597,7 +598,7 @@ func New(
app.cdc,
homePath,
app.BaseApp,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)
// register the staking hooks
// NOTE: StakingKeeper above is passed by reference, so that it will contain these hooks
Expand Down Expand Up @@ -695,6 +696,7 @@ func New(
&app.Rewardskeeper,
&app.VaultKeeper,
&app.BandoracleKeeper,
govModAddress,
)

app.LendKeeper = lendkeeper.NewKeeper(
Expand Down Expand Up @@ -722,6 +724,7 @@ func New(
&app.MarketKeeper,
&app.TokenmintKeeper,
&app.CollectorKeeper,
govModAddress,
)

app.VaultKeeper = vaultkeeper.NewKeeper(
Expand Down Expand Up @@ -872,6 +875,7 @@ func New(
&app.LendKeeper,
&app.NewaucKeeper,
&app.CollectorKeeper,
govModAddress,
)

app.NewaucKeeper = auctionsV2keeper.NewKeeper(
Expand All @@ -895,7 +899,7 @@ func New(
app.keys[commontypes.MemStoreKey],
app.GetSubspace(commontypes.ModuleName),
&app.WasmKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
)

// ICQ Keeper
Expand Down Expand Up @@ -943,7 +947,7 @@ func New(
wasmDir,
wasmConfig,
supportedFeatures,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
govModAddress,
wasmOpts...,
)

Expand Down Expand Up @@ -971,7 +975,7 @@ func New(

govKeeper := govkeeper.NewKeeper(
app.cdc, keys[govtypes.StoreKey], app.AccountKeeper, app.BankKeeper,
app.StakingKeeper, app.MsgServiceRouter(), govtypes.DefaultConfig(), authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.StakingKeeper, app.MsgServiceRouter(), govtypes.DefaultConfig(), govModAddress,
)

govKeeper.SetLegacyRouter(govRouter)
Expand Down
27 changes: 26 additions & 1 deletion proto/comdex/asset/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package comdex.asset.v1beta1;

import "gogoproto/gogo.proto";
import "comdex/asset/v1beta1/asset.proto";
import "comdex/asset/v1beta1/params.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/comdex-official/comdex/x/asset/types";
option (gogoproto.goproto_getters_all) = false;
Expand All @@ -11,6 +14,7 @@ option (gogoproto.goproto_getters_all) = false;
service Msg {
// AddAsset defines a method for adding new asset in asset module
rpc AddAsset(MsgAddAsset) returns (MsgAddAssetResponse);
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgAddAsset defines an SDK message for adding new asset in asset module.
Expand All @@ -19,4 +23,25 @@ message MsgAddAsset {
Asset asset = 2 [(gogoproto.nullable) = false];
}

message MsgAddAssetResponse {}
message MsgAddAssetResponse {}

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

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/asset 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: 0.47
message MsgUpdateParamsResponse {}
2 changes: 1 addition & 1 deletion proto/comdex/common/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ message MsgUpdateParams {
// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/auth parameters to update.
// params defines the x/common parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
Expand Down
29 changes: 28 additions & 1 deletion proto/comdex/esm/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ package comdex.esm.v1beta1;
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "comdex/esm/v1beta1/esm.proto";
import "comdex/esm/v1beta1/params.proto";

import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/comdex-official/comdex/x/esm/types";

Expand All @@ -12,6 +16,7 @@ service Msg {
rpc ExecuteESM(MsgExecuteESM) returns (MsgExecuteESMResponse);
rpc MsgKillSwitch(MsgKillRequest) returns (MsgKillResponse);
rpc MsgCollateralRedemption(MsgCollateralRedemptionRequest) returns (MsgCollateralRedemptionResponse);
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

message MsgDepositESM {
Expand Down Expand Up @@ -40,4 +45,26 @@ message MsgCollateralRedemptionRequest {
message MsgDepositESMResponse {}
message MsgExecuteESMResponse {}
message MsgKillResponse {}
message MsgCollateralRedemptionResponse{}
message MsgCollateralRedemptionResponse{}


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

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/esm 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: 0.47
message MsgUpdateParamsResponse {}
26 changes: 26 additions & 0 deletions proto/comdex/liquidationsV2/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package comdex.liquidationsV2.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "comdex/liquidationsV2/v1beta1/params.proto";

import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/comdex-official/comdex/x/liquidationsV2/types";
option (gogoproto.equal_all) = false;
Expand All @@ -12,6 +16,7 @@ service Msg {
rpc MsgLiquidateInternalKeeper(MsgLiquidateInternalKeeperRequest) returns (MsgLiquidateInternalKeeperResponse);
rpc MsgAppReserveFunds(MsgAppReserveFundsRequest) returns (MsgAppReserveFundsResponse);
rpc MsgLiquidateExternalKeeper(MsgLiquidateExternalKeeperRequest) returns (MsgLiquidateExternalKeeperResponse);
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

message MsgLiquidateInternalKeeperRequest {
Expand Down Expand Up @@ -76,3 +81,24 @@ message MsgLiquidateExternalKeeperRequest {

}
message MsgLiquidateExternalKeeperResponse{}

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

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/liquidationsV2 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: 0.47
message MsgUpdateParamsResponse {}
3 changes: 3 additions & 0 deletions x/asset/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Keeper struct {
rewards expected.RewardsKeeper
vault expected.VaultKeeper
bandoracle expected.Bandoraclekeeper
authority string
}

func NewKeeper(
Expand All @@ -32,6 +33,7 @@ func NewKeeper(
rewards expected.RewardsKeeper,
vault expected.VaultKeeper,
bandoracle expected.Bandoraclekeeper,
authority string,
) Keeper {
if !params.HasKeyTable() {
params = params.WithKeyTable(assettypes.ParamKeyTable())
Expand All @@ -46,6 +48,7 @@ func NewKeeper(
rewards: rewards,
vault: vault,
bandoracle: bandoracle,
authority: authority,
}
}

Expand Down
13 changes: 13 additions & 0 deletions x/asset/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package keeper

import (
"context"
"cosmossdk.io/errors"

"github.com/comdex-official/comdex/x/asset/types"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

type msgServer struct {
Expand All @@ -29,3 +31,14 @@ func (m msgServer) AddAsset(goCtx context.Context, msg *types.MsgAddAsset) (*typ

return &types.MsgAddAssetResponse{}, nil
}

func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.authority != req.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)
k.SetParams(ctx, req.Params)

return &types.MsgUpdateParamsResponse{}, nil
}
6 changes: 6 additions & 0 deletions x/asset/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package types

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

Expand All @@ -21,6 +23,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&AddAssetInAppProposal{}, "comdex/asset/AddAssetInAppProposal", nil)
cdc.RegisterConcrete(&UpdateGovTimeInAppProposal{}, "comdex/asset/UpdateGovTimeInAppProposal", nil)
cdc.RegisterConcrete(&AddMultipleAssetsPairsProposal{}, "comdex/asset/AddMultipleAssetsPairsProposal", nil)
cdc.RegisterConcrete(&Params{}, "comdex/asset/Params", nil)
legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "comdex/asset/MsgUpdateParams")
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
Expand All @@ -36,6 +40,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&AddAssetInAppProposal{},
&UpdateGovTimeInAppProposal{},
&AddMultipleAssetsPairsProposal{},
&MsgUpdateParams{},
)

registry.RegisterImplementations(
Expand All @@ -54,6 +59,7 @@ var (
func init() {
RegisterLegacyAminoCodec(amino)
cryptocodec.RegisterCrypto(amino)
RegisterLegacyAminoCodec(authzcodec.Amino)
// sdk.RegisterLegacyAminoCodec(amino)
amino.Seal()
}
Loading

0 comments on commit b23ba4b

Please sign in to comment.