Skip to content

Commit

Permalink
feat: create tickers module
Browse files Browse the repository at this point in the history
  • Loading branch information
hallazzang committed Jul 15, 2024
1 parent 2c0d9bd commit 9151ea8
Show file tree
Hide file tree
Showing 29 changed files with 4,927 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ import (
"github.com/milkyway-labs/milkyway/x/stakeibc"
stakeibckeeper "github.com/milkyway-labs/milkyway/x/stakeibc/keeper"
stakeibctypes "github.com/milkyway-labs/milkyway/x/stakeibc/types"
"github.com/milkyway-labs/milkyway/x/tickers"
tickerskeeper "github.com/milkyway-labs/milkyway/x/tickers/keeper"
tickerstypes "github.com/milkyway-labs/milkyway/x/tickers/types"
"github.com/milkyway-labs/milkyway/x/tokenfactory"
tokenfactorykeeper "github.com/milkyway-labs/milkyway/x/tokenfactory/keeper"
tokenfactorytypes "github.com/milkyway-labs/milkyway/x/tokenfactory/types"
Expand Down Expand Up @@ -293,6 +296,7 @@ type MilkyWayApp struct {
OperatorsKeeper *operatorskeeper.Keeper
PoolsKeeper *poolskeeper.Keeper
RestakingKeeper *restakingkeeper.Keeper
TickersKeeper *tickerskeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -357,6 +361,7 @@ func NewMilkyWayApp(

// Custom modules
servicestypes.StoreKey, operatorstypes.StoreKey, poolstypes.StoreKey, restakingtypes.StoreKey,
tickerstypes.StoreKey,
)
tkeys := storetypes.NewTransientStoreKeys(forwardingtypes.TransientStoreKey)
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -898,6 +903,12 @@ func NewMilkyWayApp(
app.ServicesKeeper,
authorityAddr,
)
app.TickersKeeper = tickerskeeper.NewKeeper(
app.appCodec,
runtime.NewKVStoreService(keys[tickerstypes.StoreKey]),
app.AccountKeeper,
authorityAddr,
)

/**** Module Options ****/

Expand Down Expand Up @@ -949,6 +960,7 @@ func NewMilkyWayApp(
operators.NewAppModule(appCodec, app.OperatorsKeeper),
pools.NewAppModule(appCodec, app.PoolsKeeper),
restaking.NewAppModule(appCodec, app.RestakingKeeper),
tickers.NewAppModule(appCodec, app.TickersKeeper),
)

if err := app.setupIndexer(appOpts, homePath, ac, vc, appCodec); err != nil {
Expand Down Expand Up @@ -1029,6 +1041,7 @@ func NewMilkyWayApp(
recordstypes.ModuleName, ratelimittypes.ModuleName, icacallbackstypes.ModuleName,

servicestypes.ModuleName, operatorstypes.ModuleName, poolstypes.ModuleName, restakingtypes.ModuleName,
tickerstypes.ModuleName,
}

app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down
15 changes: 15 additions & 0 deletions proto/milkyway/tickers/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";
package milkyway.tickers.v1;

import "gogoproto/gogo.proto";
import "milkyway/tickers/v1/params.proto";

option go_package = "github.com/milkyway-labs/milkyway/x/tickers/types";

// GenesisState defines the module's genesis state.
message GenesisState {
// Params defines the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];

map<string, string> tickers = 2;
}
75 changes: 75 additions & 0 deletions proto/milkyway/tickers/v1/messages.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
syntax = "proto3";
package milkyway.tickers.v1;

import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "gogoproto/gogo.proto";
import "milkyway/tickers/v1/params.proto";

option go_package = "github.com/milkyway-labs/milkyway/x/tickers/types";

// Msg defines the services module's gRPC message service.
service Msg {
option (cosmos.msg.v1.service) = true;

rpc RegisterTicker(MsgRegisterTicker) returns (MsgRegisterTickerResponse);

rpc DeregisterTicker(MsgDeregisterTicker)
returns (MsgDeregisterTickerResponse);

// UpdateParams defines a (governance) operation for updating the module
// parameters.
// The authority defaults to the x/gov module account.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

message MsgRegisterTicker {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "tickers/MsgRegisterTicker";

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

string denom = 2;

string ticker = 3;
}

message MsgRegisterTickerResponse {}

message MsgDeregisterTicker {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "tickers/MsgDeregisterTicker";

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

string denom = 2;
}

message MsgDeregisterTickerResponse {}

// MsgUpdateParams defines the message structure for the UpdateParams gRPC
// service method. It allows the authority to update the module parameters.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "tickers/MsgUpdateParams";

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

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

// MsgUpdateParamsResponse is the return value of MsgUpdateParams.
message MsgUpdateParamsResponse {}
6 changes: 6 additions & 0 deletions proto/milkyway/tickers/v1/models.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
syntax = "proto3";
package milkyway.tickers.v1;

import "gogoproto/gogo.proto";

option go_package = "github.com/milkyway-labs/milkyway/x/tickers/types";
11 changes: 11 additions & 0 deletions proto/milkyway/tickers/v1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";
package milkyway.tickers.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/milkyway-labs/milkyway/x/tickers/types";

// Params defines the parameters for the module.
message Params {}
50 changes: 50 additions & 0 deletions proto/milkyway/tickers/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
syntax = "proto3";
package milkyway.tickers.v1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "milkyway/tickers/v1/params.proto";

option go_package = "github.com/milkyway-labs/milkyway/x/tickers/types";

// Query defines the gRPC querier service.
service Query {
// Params defines a gRPC query method that returns the parameters of the
// module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/milkyway/tickers/v1/params";
}

rpc Ticker(QueryTickerRequest) returns (QueryTickerResponse) {
option (google.api.http).get = "/milkyway/tickers/v1/tickers/{denom}";
}

rpc Denoms(QueryDenomsRequest) returns (QueryDenomsResponse) {
option (google.api.http).get = "/milkyway/tickers/v1/denoms/{ticker}";
}
}

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

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
Params params = 1 [ (gogoproto.nullable) = false ];
}

message QueryTickerRequest { string denom = 1; }

message QueryTickerResponse { string ticker = 1; }

message QueryDenomsRequest {
string ticker = 1;

cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

message QueryDenomsResponse {
repeated string denoms = 1;

cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
129 changes: 129 additions & 0 deletions x/tickers/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package cli

import (
"context"
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
"github.com/spf13/cobra"

"github.com/milkyway-labs/milkyway/x/tickers/types"
)

// GetQueryCmd returns the command allowing to perform queries
func GetQueryCmd() *cobra.Command {
queryCmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

queryCmd.AddCommand(
GetCmdQueryParams(),
GetCmdQueryTicker(),
GetCmdQueryDenoms(),
)

return queryCmd
}

// GetCmdQueryParams returns the command to query the module params
func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the module parameters",
Example: fmt.Sprintf(`%s query %s params`, version.AppName, types.ModuleName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryTicker returns the command allowing to query the ticker by a denom
func GetCmdQueryTicker() *cobra.Command {
cmd := &cobra.Command{
Use: "ticker [denom]",
Short: "Query the ticker of a given denom",
Example: fmt.Sprintf(`%s query %s ticker umilk`, version.AppName, types.ModuleName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

denom := args[0]

res, err := queryClient.Ticker(cmd.Context(), &types.QueryTickerRequest{Denom: denom})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryDenoms returns the command allowing to query all the denoms for
// a given ticker
func GetCmdQueryDenoms() *cobra.Command {
cmd := &cobra.Command{
Use: "denoms [ticker]",
Short: "Query all the denoms of a given ticker",
Example: fmt.Sprintf(`%s query %s denoms MILK`, version.AppName, types.ModuleName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

ticker := args[0]

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

res, err := queryClient.Denoms(cmd.Context(), &types.QueryDenomsRequest{
Ticker: ticker, Pagination: pageReq,
})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "denoms")

return cmd
}
23 changes: 23 additions & 0 deletions x/tickers/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cli

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"

"github.com/milkyway-labs/milkyway/x/tickers/types"
)

// GetTxCmd returns a new command to perform transactions
func GetTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Tickers transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

txCmd.AddCommand()

return txCmd
}
Loading

0 comments on commit 9151ea8

Please sign in to comment.