Skip to content

Commit

Permalink
feat: add tickers module (#51)
Browse files Browse the repository at this point in the history
## Description

This PR adds a new x/tickers module.

Closes: MILK-57

<!-- Add a description of the changes that this PR introduces and the
files that
are the most critical to review. -->

---

### Author Checklist

*All items are required. Please add a note to the item if the item is
not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type
prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json)
in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR
Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building
modules](https://docs.cosmos.network/v0.44/building-modules/intro.html)
- [ ] included the necessary unit and integration
[tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go
code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable
and please add
your handle next to the items reviewed if you only reviewed selected
items.*

I have...

- [ ] confirmed the correct [type
prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json)
in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
hallazzang authored Jul 25, 2024
1 parent 4294a38 commit 18f3538
Show file tree
Hide file tree
Showing 32 changed files with 5,282 additions and 0 deletions.
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

0 comments on commit 18f3538

Please sign in to comment.