Skip to content

Commit

Permalink
refactor: unify pool query in pool manager, deprecate x/gamm, remove …
Browse files Browse the repository at this point in the history
…from CL module (#4658)

* refactor: unify pool query in pool manager, deprecate x/gamm, remove from CL module

* proto gen and deprecation lints

* Update tests/cl-go-client/main.go

Co-authored-by: Adam Tucker <adam@osmosis.team>

---------

Co-authored-by: Adam Tucker <adam@osmosis.team>
  • Loading branch information
p0mvn and czarcas7ic authored Mar 17, 2023
1 parent 862486e commit 4b7fe40
Show file tree
Hide file tree
Showing 21 changed files with 832 additions and 778 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### API breaks

* [#4336](https://github.com/osmosis-labs/osmosis/pull/4336) Move epochs module into its own go.mod
* [#4658](https://github.com/osmosis-labs/osmosis/pull/4658) Deprecate x/gamm Pool query. The new one is located in x/poolmanager.

## v15.0.0

Expand Down
14 changes: 0 additions & 14 deletions proto/osmosis/concentrated-liquidity/pool-model/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ service Query {
"/osmosis/concentratedliquidity/v1beta1/pools";
}

// Pool returns the Pool specified by the pool id
rpc Pool(QueryPoolRequest) returns (QueryPoolResponse) {
option (google.api.http).get =
"/osmosis/concentratedliquidity/v1beta1/pools/{pool_id}";
}

// Params returns concentrated liquidity module params.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get =
Expand Down Expand Up @@ -63,14 +57,6 @@ message QueryUserPositionsResponse {
[ (gogoproto.nullable) = false ];
}

//=============================== Pool
message QueryPoolRequest {
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
}
message QueryPoolResponse {
google.protobuf.Any pool = 1 [ (cosmos_proto.accepts_interface) = "PoolI" ];
}

//=============================== Pools
message QueryPoolsRequest {
// pagination defines an optional pagination for the request.
Expand Down
7 changes: 6 additions & 1 deletion proto/osmosis/gamm/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ service Query {
option (google.api.http).get = "/osmosis/gamm/v1beta1/filtered_pools";
}

// Per Pool gRPC Endpoints
// Deprecated: please use the alternative in x/poolmanager
rpc Pool(QueryPoolRequest) returns (QueryPoolResponse) {
option deprecated = true;
option (google.api.http).get = "/osmosis/gamm/v1beta1/pools/{pool_id}";
}

Expand Down Expand Up @@ -106,10 +107,14 @@ service Query {
}

//=============================== Pool
// Deprecated: please use the alternative in x/poolmanager
message QueryPoolRequest {
option deprecated = true;
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
}
// Deprecated: please use the alternative in x/poolmanager
message QueryPoolResponse {
option deprecated = true;
google.protobuf.Any pool = 1 [ (cosmos_proto.accepts_interface) = "PoolI" ];
}

Expand Down
15 changes: 15 additions & 0 deletions proto/osmosis/poolmanager/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ service Query {
"/osmosis/gamm/v1beta1/{pool_id}/estimate/swap_exact_amount_out";
}

// Returns the total number of pools existing in Osmosis.
rpc NumPools(NumPoolsRequest) returns (NumPoolsResponse) {
option (google.api.http).get = "/osmosis/poolmanager/v1beta1/num_pools";
}

// Pool returns the Pool specified by the pool id
rpc Pool(PoolRequest) returns (PoolResponse) {
option (google.api.http).get =
"/osmosis/poolmanager/v1beta1/pools/{pool_id}";
}
}

//=============================== Params
Expand Down Expand Up @@ -88,3 +95,11 @@ message NumPoolsRequest {}
message NumPoolsResponse {
uint64 num_pools = 1 [ (gogoproto.moretags) = "yaml:\"num_pools\"" ];
}

//=============================== Pool
message PoolRequest {
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
}
message PoolResponse {
google.protobuf.Any pool = 1 [ (cosmos_proto.accepts_interface) = "PoolI" ];
}
5 changes: 5 additions & 0 deletions proto/osmosis/poolmanager/v1beta1/query.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ queries:
query_func: "k.NumPools"
cli:
cmd: "NumPools"
Pool:
proto_wrapper:
query_func: "k.Pool"
cli:
cmd: "Pool"
8 changes: 4 additions & 4 deletions tests/cl-go-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
cl "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity"
"github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/model"
cltypes "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types"
clquery "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types/query"
poolmanagerqueryproto "github.com/osmosis-labs/osmosis/v15/x/poolmanager/client/queryproto"
)

const (
Expand Down Expand Up @@ -62,11 +62,11 @@ func main() {

log.Println("connected to: ", "chain-id", statusResp.NodeInfo.Network, "height", statusResp.SyncInfo.LatestBlockHeight)

// Instantiate a query client for your `blog` blockchain
clQueryClient := clquery.NewQueryClient(igniteClient.Context())
// Instantiate a query client
clQueryClient := poolmanagerqueryproto.NewQueryClient(igniteClient.Context())

// Query pool with id 1 and create new if does not exist.
_, err = clQueryClient.Pool(ctx, &clquery.QueryPoolRequest{PoolId: expectedPoolId})
_, err = clQueryClient.Pool(ctx, &poolmanagerqueryproto.PoolRequest{PoolId: expectedPoolId})
if err != nil {
if !strings.Contains(err.Error(), cltypes.PoolNotFoundError{PoolId: expectedPoolId}.Error()) {
log.Fatal(err)
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/configurer/chain/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
cltypes "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types"
"github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types/query"
gammtypes "github.com/osmosis-labs/osmosis/v15/x/gamm/types"
poolmanagerqueryproto "github.com/osmosis-labs/osmosis/v15/x/poolmanager/client/queryproto"
poolmanagertypes "github.com/osmosis-labs/osmosis/v15/x/poolmanager/types"
protorevtypes "github.com/osmosis-labs/osmosis/v15/x/protorev/types"
superfluidtypes "github.com/osmosis-labs/osmosis/v15/x/superfluid/types"
Expand Down Expand Up @@ -281,11 +282,11 @@ func (n *NodeConfig) QueryConcentratedPositions(address string) []model.Position
return positionsResponse.Positions
}
func (n *NodeConfig) QueryConcentratedPool(poolId uint64) (cltypes.ConcentratedPoolExtension, error) {
path := fmt.Sprintf("/osmosis/concentratedliquidity/v1beta1/pools/%d", poolId)
path := fmt.Sprintf("/osmosis/poolmanager/v1beta1/pools/%d", poolId)
bz, err := n.QueryGRPCGateway(path)
require.NoError(n.t, err)

var poolResponse query.QueryPoolResponse
var poolResponse poolmanagerqueryproto.PoolResponse
err = util.Cdc.UnmarshalJSON(bz, &poolResponse)
require.NoError(n.t, err)

Expand Down
9 changes: 0 additions & 9 deletions x/concentrated-liquidity/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
// GetQueryCmd returns the cli query commands for this module.
func GetQueryCmd() *cobra.Command {
cmd := osmocli.QueryIndexCmd(types.ModuleName)
osmocli.AddQueryCmd(cmd, query.NewQueryClient, GetCmdPool)
osmocli.AddQueryCmd(cmd, query.NewQueryClient, GetCmdPools)
osmocli.AddQueryCmd(cmd, query.NewQueryClient, GetUserPositions)
osmocli.AddQueryCmd(cmd, query.NewQueryClient, GetClaimableFees)
Expand All @@ -34,14 +33,6 @@ func GetUserPositions() (*osmocli.QueryDescriptor, *query.QueryUserPositionsRequ
&query.QueryUserPositionsRequest{}
}

func GetCmdPool() (*osmocli.QueryDescriptor, *query.QueryPoolRequest) {
return &osmocli.QueryDescriptor{
Use: "pool [poolID]",
Short: "Query pool",
Long: `{{.Short}}{{.ExampleHeader}}
{{.CommandPrefix}} pool 1`}, &query.QueryPoolRequest{}
}

func GetCmdPools() (*osmocli.QueryDescriptor, *query.QueryPoolsRequest) {
return &osmocli.QueryDescriptor{
Use: "pools",
Expand Down
23 changes: 0 additions & 23 deletions x/concentrated-liquidity/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,6 @@ func NewQuerier(k Keeper) Querier {
return Querier{Keeper: k}
}

// Pool checks if a pool exists and returns the desired pool.
func (q Querier) Pool(
ctx context.Context,
req *clquery.QueryPoolRequest,
) (*clquery.QueryPoolResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
sdkCtx := sdk.UnwrapSDKContext(ctx)

pool, err := q.Keeper.GetPool(sdkCtx, req.PoolId)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

any, err := codectypes.NewAnyWithValue(pool)
if err != nil {
return nil, err
}

return &clquery.QueryPoolResponse{Pool: any}, nil
}

// UserPositions returns positions of a specified address
func (q Querier) UserPositions(ctx context.Context, req *clquery.QueryUserPositionsRequest) (*clquery.QueryUserPositionsResponse, error) {
if req == nil {
Expand Down
Loading

0 comments on commit 4b7fe40

Please sign in to comment.