-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description This PR adds the `x/pools` module, which allows to create and query restaking pools. Depends-On: #7 Closes: MILK-45 <!-- 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... - [x] 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 - [x] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html) - [x] 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` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] 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
Showing
31 changed files
with
4,301 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
syntax = "proto3"; | ||
package milkyway.pools.v1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/protobuf/timestamp.proto"; | ||
import "milkyway/pools/v1/models.proto"; | ||
|
||
option go_package = "github.com/milkyway-labs/milkyway/x/pools/types"; | ||
|
||
// GenesisState defines the pools module's genesis state. | ||
message GenesisState { | ||
|
||
// NextPoolID represents the id to be used when creating the next pool. | ||
uint32 next_pool_id = 1 [ | ||
(gogoproto.customname) = "NextPoolID", | ||
(gogoproto.moretags) = "yaml:\"next_pool_id\"" | ||
]; | ||
|
||
// Operators defines the list of pools. | ||
repeated Pool pools = 2 | ||
[ (gogoproto.moretags) = "yaml:\"pools\"", (gogoproto.nullable) = false ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
syntax = "proto3"; | ||
package milkyway.pools.v1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
|
||
option go_package = "github.com/milkyway-labs/milkyway/x/pools/types"; | ||
|
||
// Pool defines the structure of a restaking pool | ||
message Pool { | ||
// ID is the auto-generated unique identifier for the pool | ||
uint32 id = 1 [ (gogoproto.customname) = "ID" ]; | ||
|
||
// Denom represents the denomination of the tokens that are staked in the pool | ||
string denom = 2; | ||
|
||
// Address represents the address of the account that is associated with this | ||
// pool. This will be used to store tokens that users delegate to this pool. | ||
string address = 3 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
syntax = "proto3"; | ||
package milkyway.pools.v1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/api/annotations.proto"; | ||
import "cosmos/base/query/v1beta1/pagination.proto"; | ||
import "milkyway/pools/v1/models.proto"; | ||
|
||
option go_package = "github.com/milkyway-labs/milkyway/x/pools/types"; | ||
|
||
// Query defines the gRPC querier service. | ||
service Query { | ||
// PoolById defines a gRPC query method that returns the pool by the given ID. | ||
rpc PoolById(QueryPoolByIdRequest) returns (QueryPoolResponse) { | ||
option (google.api.http).get = "/milkyway/pool/v1/pool/{pool_id}"; | ||
} | ||
|
||
// PoolByDenom defines a gRPC query method that returns the pool by the given | ||
// denom. | ||
rpc PoolByDenom(QueryPoolByDenomRequest) returns (QueryPoolResponse) { | ||
option (google.api.http).get = "/milkyway/pool/v1/pool/denom/{denom}"; | ||
} | ||
|
||
// Pools defines a gRPC query method that returns all pools. | ||
rpc Pools(QueryPoolsRequest) returns (QueryPoolsResponse) { | ||
option (google.api.http).get = "/milkyway/pool/v1/pools"; | ||
} | ||
} | ||
|
||
// QueryPoolByIdRequest is the request type for the Query/PoolById RPC method. | ||
message QueryPoolByIdRequest { | ||
// PoolID is the ID of the pool to query | ||
uint32 pool_id = 1; | ||
} | ||
|
||
// QueryPoolByDenomRequest is the request type for the Query/PollByDenom RPC | ||
// method. | ||
message QueryPoolByDenomRequest { | ||
// Denom is the denom for which the pool is to be queried | ||
string denom = 1; | ||
} | ||
|
||
// QueryOperatorRPoolsesponse is the response type for the Query/PoolById and | ||
// Query/PoolByDenom RPC methods. | ||
message QueryPoolResponse { | ||
// Pool is the queried pool | ||
Pool pool = 1 [ (gogoproto.nullable) = false ]; | ||
} | ||
|
||
// QueryPoolsRequest is the request type for the Query/Pools RPC method. | ||
message QueryPoolsRequest { | ||
cosmos.base.query.v1beta1.PageRequest pagination = 1; | ||
} | ||
|
||
// QueryPoolsResponse is the response type for the Query/Pools RPC method. | ||
message QueryPoolsResponse { | ||
// Pools is the list of pool | ||
repeated Pool pools = 1 [ (gogoproto.nullable) = false ]; | ||
|
||
// Pagination defines the pagination response | ||
cosmos.base.query.v1beta1.PageResponse pagination = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package cli | ||
|
||
import ( | ||
"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/pools/types" | ||
) | ||
|
||
// GetQueryCmd returns the command allowing to perform queries | ||
func GetQueryCmd() *cobra.Command { | ||
servicesQueryCmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
servicesQueryCmd.AddCommand( | ||
getCmdQueryPoolByID(), | ||
getCmdQueryPoolByDenom(), | ||
getCmdQueryPools(), | ||
) | ||
|
||
return servicesQueryCmd | ||
} | ||
|
||
// getCmdQueryPoolByID returns the command allowing to query a service | ||
func getCmdQueryPoolByID() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "pool [pool-id]", | ||
Short: "Query the pool with the given id", | ||
Example: fmt.Sprintf(`%s query %s pool 1`, 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) | ||
|
||
poolID, err := types.ParsePoolID(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res, err := queryClient.PoolById(cmd.Context(), types.NewQueryPoolByIdRequest(poolID)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
// getCmdQueryPoolByDenom returns the command allowing to query services | ||
func getCmdQueryPoolByDenom() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "pool-by-denom [denom]", | ||
Short: "Query the pool associated with the given denom", | ||
Example: fmt.Sprintf(`%s query %s pool 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) | ||
|
||
res, err := queryClient.PoolByDenom(cmd.Context(), types.NewQueryPoolByDenomRequest(args[0])) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
// getCmdQueryPools returns the command to query the stored pools | ||
func getCmdQueryPools() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "pools", | ||
Short: "Query the pools", | ||
Example: fmt.Sprintf(`%s query %s pools --page=2 --limit=100`, 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) | ||
|
||
pageReq, err := client.ReadPageRequest(cmd.Flags()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res, err := queryClient.Pools(cmd.Context(), types.NewQueryPoolsRequest(pageReq)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
flags.AddPaginationFlagsToCmd(cmd, "pools") | ||
|
||
return cmd | ||
} |
Oops, something went wrong.