Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tickers module #51

Merged
merged 4 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 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,11 @@ func NewMilkyWayApp(
app.ServicesKeeper,
authorityAddr,
)
app.TickersKeeper = tickerskeeper.NewKeeper(
app.appCodec,
runtime.NewKVStoreService(keys[tickerstypes.StoreKey]),
authorityAddr,
)

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

Expand Down Expand Up @@ -949,6 +959,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 +1040,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
26 changes: 26 additions & 0 deletions app/testutil/test_suite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package testutil

import (
"time"

"cosmossdk.io/core/header"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"

milkywayapp "github.com/milkyway-labs/milkyway/app"
)

type KeeperTestSuite struct {
suite.Suite

App *milkywayapp.MilkyWayApp
Ctx sdk.Context
}

func (s *KeeperTestSuite) SetupTest() {
s.App = milkywayapp.SetupWithGenesisAccounts(nil, nil)
s.Ctx = s.App.NewContext(true).WithHeaderInfo(header.Info{
Height: s.App.LastBlockHeight(),
Time: time.Time{},
})
}
17 changes: 17 additions & 0 deletions proto/milkyway/tickers/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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 ];

// Tickers defines the denom-ticker map. Key is a denom and value is its
// ticker.
map<string, string> tickers = 2;
}
88 changes: 88 additions & 0 deletions proto/milkyway/tickers/v1/messages.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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;

// RegisterTicker defines the operation for registering a ticker.
rpc RegisterTicker(MsgRegisterTicker) returns (MsgRegisterTickerResponse);

// DeregisterTicker defines the operation for de-registering a ticker with
// the token denomination.
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);
}

// MsgRegisterTicker defines the message structure for the RegisterTicker
// gRPC service method. It allows the authority to register a ticker.
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" ];

// Denom represents the denomination of the token associated with the ticker.
string denom = 2;

// Ticker represents the ticker of the token denomination.
string ticker = 3;
}

// MsgRegisterTickerResponse is the return value of MsgRegisterTicker.
message MsgRegisterTickerResponse {}

// MsgDeregisterTicker defines the message structure for the DeregisterTicker
// gRPC service method. It allows the authority to de-register a ticker with
// the token denomination.
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" ];

// Denom represents the denomination of the token associated with the ticker.
string denom = 2;
}

// MsgRegisterTickerResponse is the return value of MsgDeregisterTicker.
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 {}
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 {}
67 changes: 67 additions & 0 deletions proto/milkyway/tickers/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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";
}

// Ticker defines a gRPC query method that returns a ticker of the given
// token denomination.
rpc Ticker(QueryTickerRequest) returns (QueryTickerResponse) {
option (google.api.http).get = "/milkyway/tickers/v1/tickers/{denom}";
}

// Denoms defines a gRPC query method that returns all the token
// denominations associated with the given ticker.
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 ];
}

// QueryTickerRequest is the request type for the Query/Ticker RPC method.
message QueryTickerRequest {
// Denom is the token denomination for which the ticker is to be queried.
string denom = 1;
}

// QueryTickerResponse is the response type for the Query/Ticker RPC method.
message QueryTickerResponse {
// Ticker is the ticker of the given token denomination.
string ticker = 1;
}

// QueryDenomsRequest is the request type for the Query/Denoms RPC method.
message QueryDenomsRequest {
// Ticker is the ticker for which the denoms are to be queried.
string ticker = 1;

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

// QueryDenomsResponse is the response type for the Query/Denoms RPC method.
message QueryDenomsResponse {
// Denom is the list of all the token denominations associated with the
// ticker.
repeated string denoms = 1;

cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
Loading
Loading