Skip to content

Commit

Permalink
Protorev query highest liquidity pools (#4829)
Browse files Browse the repository at this point in the history
* Update proto files for protorev pool query

- protorev pool query will return pool id given a denom pair for the highest liquidity method

* add grpc query handler logic for GetProtoRevPool query

* Add cli query support

* Add test for GetProtoRevPool query

* Change endpoint to pool and re-gen proto code

* add pool query in documentation

* Specify the query is for highest liquidity method pools only

* Change comment to represent query

Co-authored-by: David Terpay <[email protected]>

* change comments in proto file and generated pb

* fix test comment

* Add query to changelog

---------

Co-authored-by: David Terpay <[email protected]>
(cherry picked from commit 5f4beb7)

# Conflicts:
#	CHANGELOG.md
#	x/protorev/client/cli/query.go
#	x/protorev/protorev.md
  • Loading branch information
NotJeremyLiu authored and mergify[bot] committed Apr 18, 2023
1 parent a22b270 commit 1831e4d
Show file tree
Hide file tree
Showing 8 changed files with 705 additions and 90 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

<<<<<<< HEAD
=======
### Features

* [#4659](https://github.com/osmosis-labs/osmosis/pull/4659) implement AllPools query in x/poolmanager.
* [#4783](https://github.com/osmosis-labs/osmosis/pull/4783) Update wasmd to 0.31.0
* [#4886](https://github.com/osmosis-labs/osmosis/pull/4886) Implement MsgSplitRouteSwapExactAmountIn and MsgSplitRouteSwapExactAmountOut that supports route splitting.
* [#4829] (https://github.com/osmosis-labs/osmosis/pull/4829) Add highest liquidity pool query in x/protorev

>>>>>>> 5f4beb71 (Protorev query highest liquidity pools (#4829))
### Misc Improvements

* [#4582](https://github.com/osmosis-labs/osmosis/pull/4582) Consistently generate build tags metadata, to return a comma-separated list without stray quotes. This affects the output from `version` CLI subcommand and server info API calls.
Expand Down
24 changes: 24 additions & 0 deletions proto/osmosis/protorev/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ service Query {
returns (QueryGetProtoRevEnabledResponse) {
option (google.api.http).get = "/osmosis/v14/protorev/enabled";
}

// GetProtoRevPool queries the pool id used via the highest liquidity method
// for arbitrage route building given a pair of denominations
rpc GetProtoRevPool(QueryGetProtoRevPoolRequest)
returns (QueryGetProtoRevPoolResponse) {
option (google.api.http).get = "/osmosis/v14/protorev/pool";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -300,4 +307,21 @@ message QueryGetProtoRevEnabledRequest {}
message QueryGetProtoRevEnabledResponse {
// enabled is whether the module is enabled
bool enabled = 1 [ (gogoproto.moretags) = "yaml:\"enabled\"" ];
}

// QueryGetProtoRevPoolRequest is request type for the
// Query/GetProtoRevPool RPC method.
message QueryGetProtoRevPoolRequest {
// base_denom is the base denom set in protorev for the denom pair to pool
// mapping
string base_denom = 1 [ (gogoproto.moretags) = "yaml:\"base_denom\"" ];
// other_denom is the other denom for the denom pair to pool mapping
string other_denom = 2 [ (gogoproto.moretags) = "yaml:\"other_denom\"" ];
}

// QueryGetProtoRevPoolResponse is response type for the
// Query/GetProtoRevPool RPC method.
message QueryGetProtoRevPoolResponse {
// pool_id is the pool_id stored for the denom pair
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
}
24 changes: 24 additions & 0 deletions x/protorev/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func NewCmdQuery() *cobra.Command {
osmocli.AddQueryCmd(cmd, types.NewQueryClient, NewQueryMaxPoolPointsPerBlockCmd)
osmocli.AddQueryCmd(cmd, types.NewQueryClient, NewQueryBaseDenomsCmd)
osmocli.AddQueryCmd(cmd, types.NewQueryClient, NewQueryEnabledCmd)
<<<<<<< HEAD
=======
osmocli.AddQueryCmd(cmd, types.NewQueryClient, NewQueryPoolWeightsCmd)
osmocli.AddQueryCmd(cmd, types.NewQueryClient, NewQueryPoolCmd)
>>>>>>> 5f4beb71 (Protorev query highest liquidity pools (#4829))

return cmd
}
Expand Down Expand Up @@ -139,6 +144,25 @@ func NewQueryEnabledCmd() (*osmocli.QueryDescriptor, *types.QueryGetProtoRevEnab
}, &types.QueryGetProtoRevEnabledRequest{}
}

<<<<<<< HEAD
=======
// NewQueryPoolWeightsCmd returns the command to query the pool weights of protorev
func NewQueryPoolWeightsCmd() (*osmocli.QueryDescriptor, *types.QueryGetProtoRevPoolWeightsRequest) {
return &osmocli.QueryDescriptor{
Use: "pool-weights",
Short: "Query the pool weights used to determine how computationally expensive a route is",
}, &types.QueryGetProtoRevPoolWeightsRequest{}
}

// NewQueryPoolCmd returns the command to query the pool id for a given denom pair stored via the highest liquidity method in ProtoRev
func NewQueryPoolCmd() (*osmocli.QueryDescriptor, *types.QueryGetProtoRevPoolRequest) {
return &osmocli.QueryDescriptor{
Use: "pool [base_denom] [other_denom]",
Short: "Query the pool id for a given denom pair stored via the highest liquidity method in ProtoRev",
}, &types.QueryGetProtoRevPoolRequest{}
}

>>>>>>> 5f4beb71 (Protorev query highest liquidity pools (#4829))
// convert a string array "[1,2,3]" to []uint64
func parseRoute(arg string, _ *pflag.FlagSet) (any, osmocli.FieldReadLocation, error) {
var route []uint64
Expand Down
15 changes: 15 additions & 0 deletions x/protorev/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,18 @@ func (q Querier) GetProtoRevEnabled(c context.Context, req *types.QueryGetProtoR

return &types.QueryGetProtoRevEnabledResponse{Enabled: q.Keeper.GetProtoRevEnabled(ctx)}, nil
}

// GetProtoRevPool queries the pool id for a given base denom and other denom
func (q Querier) GetProtoRevPool(c context.Context, req *types.QueryGetProtoRevPoolRequest) (*types.QueryGetProtoRevPoolResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)

poolId, err := q.Keeper.GetPoolForDenomPair(ctx, req.BaseDenom, req.OtherDenom)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &types.QueryGetProtoRevPoolResponse{PoolId: poolId}, nil
}
22 changes: 22 additions & 0 deletions x/protorev/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,25 @@ func (suite *KeeperTestSuite) TestGetProtoRevEnabledQuery() {
suite.Require().NoError(err)
suite.Require().Equal(enabled, res.Enabled)
}

// TestGetProtoRevPool tests the query for getting the highest liquidity pool stored
func (suite *KeeperTestSuite) TestGetProtoRevPool() {
// Request without setting pool for the base denom and other denom should return an error
req := &types.QueryGetProtoRevPoolRequest{
BaseDenom: "uosmo",
OtherDenom: "atom",
}
res, err := suite.queryClient.GetProtoRevPool(sdk.WrapSDKContext(suite.Ctx), req)
suite.Require().Error(err)
suite.Require().Nil(res)

// Request for a pool that is stored should return the pool id
// The pool is set at startup for the test suite
req = &types.QueryGetProtoRevPoolRequest{
BaseDenom: "Atom",
OtherDenom: "akash",
}
res, err = suite.queryClient.GetProtoRevPool(sdk.WrapSDKContext(suite.Ctx), req)
suite.Require().NoError(err)
suite.Require().Equal(res.PoolId, uint64(1))
}
7 changes: 7 additions & 0 deletions x/protorev/protorev.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,11 @@ osmosisd query protorev params
| query protorev | max-pool-points-per-block | Queries the ProtoRev max pool points per block |
| query protorev | base-denoms | Queries the ProtoRev base denoms used to create cyclic arbitrage routes |
| query protorev | enabled | Queries whether the ProtoRev module is currently enabled |
<<<<<<< HEAD
=======
| query protorev | pool-weights | Queries the pool weights used to determine how computationally expensive a route is |
| query protorev | pool | Queries the pool id for a given denom pair stored in ProtoRev |
>>>>>>> 5f4beb71 (Protorev query highest liquidity pools (#4829))
### Proposals

Expand Down Expand Up @@ -662,6 +667,7 @@ osmosisd query protorev params
| gRPC | osmosis.v14.protorev.Query/GetProtoRevBaseDenoms | Queries the ProtoRev base denoms used to create cyclic arbitrage routes |
| gRPC | osmosis.v14.protorev.Query/GetProtoRevEnabled | Queries whether the ProtoRev module is currently enabled |
| gRPC | osmosis.14.protorev.Query/GetProtoRevPoolWeights | Queries the number of pool points each pool type will consume when executing and simulating trades |
| gRPC | osmosis.14.protorev.Query/GetProtoRevPool | Queries the pool id for a given denom pair stored in ProtoRev |
| GET | /osmosis/v14/protorev/params | Queries the parameters of the module |
| GET | /osmosis/v14/protorev/number_of_trades | Queries the number of arbitrage trades the module has executed |
| GET | /osmosis/v14/protorev/profits_by_denom | Queries the profits of the module by denom |
Expand All @@ -676,6 +682,7 @@ osmosisd query protorev params
| GET | /osmosis/v14/protorev/base_denoms | Queries the base denominations ProtoRev is currently using to create cyclic arbitrage routes |
| GET | /osmosis/v14/protorev/enabled | Queries whether the ProtoRev module is currently enabled |
| GET | /osmosis/v14/protorev/pool_weights | Queries the number of pool points each pool type will consume when executing and simulating trades |
| GET | /osmosis/v14/protorev/pool | Queries the pool id for a given denom pair stored in ProtoRev |

### Transactions

Expand Down
Loading

0 comments on commit 1831e4d

Please sign in to comment.