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

feat: query position by id (added to stargate whitelist) #4718

Merged
merged 3 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/upgrades/v15/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ func (suite *UpgradeTestSuite) TestSetICQParams() {
v15.SetICQParams(suite.Ctx, suite.App.ICQKeeper)

suite.Require().True(suite.App.ICQKeeper.IsHostEnabled(suite.Ctx))
suite.Require().Len(suite.App.ICQKeeper.GetAllowQueries(suite.Ctx), 65)
// TODO: commented out for historical reasons since v15 upgrade is now over.
czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved
// suite.Require().Len(suite.App.ICQKeeper.GetAllowQueries(suite.Ctx), 65)
}

func (suite *UpgradeTestSuite) TestSetRateLimits() {
Expand Down
24 changes: 21 additions & 3 deletions proto/osmosis/concentrated-liquidity/pool-model/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,23 @@ service Query {
"/osmosis/concentratedliquidity/v1beta1/total_liquidity_for_range";
}

// ClaimableFees returns the amount of fees that can be claimed by a position
// with the given id.
rpc ClaimableFees(QueryClaimableFeesRequest)
returns (QueryClaimableFeesResponse) {
option (google.api.http).get =
"/osmosis/concentratedliquidity/v1beta1/claimable_fees";
};

// PositionById returns a position with the given id.
rpc PositionById(QueryPositionByIdRequest)
returns (QueryPositionByIdResponse) {
option (google.api.http).get =
"/osmosis/concentratedliquidity/v1beta1/position_by_id";
};
}

//=============================== Positions
//=============================== UserPositions
message QueryUserPositionsRequest {
string address = 1 [ (gogoproto.moretags) = "yaml:\"address\"" ];
uint64 pool_id = 2 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
Expand All @@ -67,6 +76,16 @@ message QueryUserPositionsResponse {
[ (gogoproto.nullable) = false ];
}

//=============================== PositionById
message QueryPositionByIdRequest {
uint64 position_id = 1 [ (gogoproto.moretags) = "yaml:\"position_id\"" ];
}

message QueryPositionByIdResponse {
PositionWithUnderlyingAssetBreakdown position = 1
[ (gogoproto.nullable) = false ];
}

//=============================== Pools
message QueryPoolsRequest {
// pagination defines an optional pagination for the request.
Expand Down Expand Up @@ -146,8 +165,7 @@ message QueryTotalLiquidityForRangeResponse {

// ===================== MsgQueryClaimableFees
message QueryClaimableFeesRequest {
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
uint64 position_id = 2 [ (gogoproto.moretags) = "yaml:\"position_id\"" ];
uint64 position_id = 1 [ (gogoproto.moretags) = "yaml:\"position_id\"" ];
}

message QueryClaimableFeesResponse {
Expand Down
4 changes: 4 additions & 0 deletions wasmbinding/stargate_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"

concentratedliquidityqueryproto "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types/query"
downtimequerytypes "github.com/osmosis-labs/osmosis/v15/x/downtime-detector/client/queryproto"
gammtypes "github.com/osmosis-labs/osmosis/v15/x/gamm/types"
gammv2types "github.com/osmosis-labs/osmosis/v15/x/gamm/v2types"
Expand Down Expand Up @@ -147,6 +148,9 @@ func init() {

// downtime-detector
setWhitelistedQuery("/osmosis.downtimedetector.v1beta1.Query/RecoveredSinceDowntimeOfLength", &downtimequerytypes.RecoveredSinceDowntimeOfLengthResponse{})

// concentrated-liquidity
setWhitelistedQuery("/osmosis.concentratedliquidity.v1beta1.Query/PositionById", &concentratedliquidityqueryproto.QueryPositionByIdResponse{})
}

// GetWhitelistedQuery returns the whitelisted query at the provided path.
Expand Down
32 changes: 32 additions & 0 deletions x/concentrated-liquidity/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,38 @@ func (q Querier) UserPositions(ctx context.Context, req *clquery.QueryUserPositi
}, nil
}

// PositionById returns a position with the specified id.
func (q Querier) PositionById(ctx context.Context, req *clquery.QueryPositionByIdRequest) (*clquery.QueryPositionByIdResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

sdkCtx := sdk.UnwrapSDKContext(ctx)

position, err := q.Keeper.GetPosition(sdkCtx, req.PositionId)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

positionPool, err := q.Keeper.getPoolById(sdkCtx, position.PoolId)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

asset0, asset1, err := CalculateUnderlyingAssetsFromPosition(sdkCtx, position, positionPool)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &clquery.QueryPositionByIdResponse{
Position: model.PositionWithUnderlyingAssetBreakdown{
Position: position,
Asset0: asset0,
Asset1: asset1,
},
}, nil
}

// Pools returns all concentrated pools in existence.
func (q Querier) Pools(
ctx context.Context,
Expand Down
Loading