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

Protorev query highest liquidity pools #4829

Merged
merged 11 commits into from
Apr 18, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#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

### Misc Improvements

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\"" ];
}
9 changes: 9 additions & 0 deletions x/protorev/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func NewCmdQuery() *cobra.Command {
osmocli.AddQueryCmd(cmd, types.NewQueryClient, NewQueryBaseDenomsCmd)
osmocli.AddQueryCmd(cmd, types.NewQueryClient, NewQueryEnabledCmd)
osmocli.AddQueryCmd(cmd, types.NewQueryClient, NewQueryPoolWeightsCmd)
osmocli.AddQueryCmd(cmd, types.NewQueryClient, NewQueryPoolCmd)

return cmd
}
Expand Down Expand Up @@ -148,6 +149,14 @@ func NewQueryPoolWeightsCmd() (*osmocli.QueryDescriptor, *types.QueryGetProtoRev
}, &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{}
}

// 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))
}
3 changes: 3 additions & 0 deletions x/protorev/protorev.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ osmosisd query protorev params
| 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 |
| 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 |

### Proposals

Expand Down Expand Up @@ -669,6 +670,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 @@ -683,6 +685,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