Skip to content

Commit

Permalink
feat[CL]: add num initialized ticks query (#6416)
Browse files Browse the repository at this point in the history
* add num initialized ticks query

* update changelog

* Generated protofile changes

* add max number of initialized ticks to return

* Generated protofile changes

* remove limit

* update query.yml

* add go test

---------

Co-authored-by: devbot-wizard <[email protected]>
Co-authored-by: github-actions <[email protected]>
(cherry picked from commit 9f664d7)

# Conflicts:
#	CHANGELOG.md
#	x/concentrated-liquidity/client/queryproto/query.pb.go
  • Loading branch information
czarcas7ic authored and mergify[bot] committed Sep 15, 2023
1 parent 421d6a9 commit 0f04b1b
Show file tree
Hide file tree
Showing 11 changed files with 1,237 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

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

* [#6416](https://github.com/osmosis-labs/osmosis/pull/6416) feat[CL]: add num initialized ticks query

### State Breaking

* [#6344](https://github.com/osmosis-labs/osmosis/pull/6344) fix: set name, display and symbol of denom metadata in tokenfactory's CreateDenom
* [#6279](https://github.com/osmosis-labs/osmosis/pull/6279) fix prop-597 introduced issue
* [#6282](https://github.com/osmosis-labs/osmosis/pull/6282) Fix CreateCanonicalConcentratedLiquidityPoolAndMigrationLink overriding migration records

>>>>>>> 9f664d71 (feat[CL]: add num initialized ticks query (#6416))
### Bug Fixes

* [#6334](https://github.com/osmosis-labs/osmosis/pull/6334) fix: enable taker fee cli
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
cosmossdk.io/errors v1.0.0
github.com/CosmWasm/wasmd v0.31.0
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.47.4
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4 v4.1.0
github.com/cosmos/ibc-apps/modules/async-icq/v4 v4.1.0
Expand Down
28 changes: 28 additions & 0 deletions proto/osmosis/concentrated-liquidity/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ service Query {
option (google.api.http).get =
"/osmosis/concentratedliquidity/v1beta1/get_total_liquidity";
}

// NumNextInitializedTicks returns the provided number of next initialized
// ticks in the direction of swapping the token in denom.
rpc NumNextInitializedTicks(NumNextInitializedTicksRequest)
returns (NumNextInitializedTicksResponse) {
option (google.api.http).get = "/osmosis/concentratedliquidity/v1beta1/"
"num_next_initialized_ticks";
}
}

//=============================== UserPositions
Expand Down Expand Up @@ -315,3 +323,23 @@ message GetTotalLiquidityResponse {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

//=============================== NumNextInitializedTicks
message NumNextInitializedTicksRequest {
uint64 pool_id = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
string token_in_denom = 2
[ (gogoproto.moretags) = "yaml:\"token_in_denom\"" ];
uint64 num_next_initialized_ticks = 3
[ (gogoproto.moretags) = "yaml:\"num_next_initialized_ticks\"" ];
}
message NumNextInitializedTicksResponse {
repeated TickLiquidityNet liquidity_depths = 1
[ (gogoproto.nullable) = false ];
int64 current_tick = 2;
string current_liquidity = 3 [

(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.moretags) = "yaml:\"current_liquidity\"",
(gogoproto.nullable) = false
];
}
5 changes: 5 additions & 0 deletions proto/osmosis/concentrated-liquidity/query.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ queries:
query_func: "k.GetTotalLiquidity"
cli:
cmd: "GetTotalLiquidity"
NumNextInitializedTicks:
proto_wrapper:
query_func: "k.NumNextInitializedTicks"
cli:
cmd: "NumNextInitializedTicks"
10 changes: 10 additions & 0 deletions x/concentrated-liquidity/client/grpc/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ func (q Querier) Params(grpcCtx context.Context,
return q.Q.Params(ctx, *req)
}

func (q Querier) NumNextInitializedTicks(grpcCtx context.Context,
req *queryproto.NumNextInitializedTicksRequest,
) (*queryproto.NumNextInitializedTicksResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(grpcCtx)
return q.Q.NumNextInitializedTicks(ctx, *req)
}

func (q Querier) LiquidityPerTickRange(grpcCtx context.Context,
req *queryproto.LiquidityPerTickRangeRequest,
) (*queryproto.LiquidityPerTickRangeResponse, error) {
Expand Down
25 changes: 25 additions & 0 deletions x/concentrated-liquidity/client/query_proto_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,28 @@ func (q Querier) GetTotalLiquidity(ctx sdk.Context, req clquery.GetTotalLiquidit
TotalLiquidity: totalLiquidity,
}, nil
}

// NumNextInitializedTicks returns an array of LiquidityDepthWithRange, which contains the user defined number of next initialized ticks in the direction
// of swapping in the given tokenInDenom.
func (q Querier) NumNextInitializedTicks(ctx sdk.Context, req clquery.NumNextInitializedTicksRequest) (*clquery.NumNextInitializedTicksResponse, error) {
if req.TokenInDenom == "" {
return nil, status.Error(codes.InvalidArgument, "tokenIn is empty")
}

liquidityDepths, err := q.Keeper.GetNumNextInitializedTicks(
ctx,
req.PoolId,
req.NumNextInitializedTicks,
req.TokenInDenom,
)
if err != nil {
return nil, err
}

pool, err := q.Keeper.GetConcentratedPoolById(ctx, req.PoolId)
if err != nil {
return nil, err
}

return &clquery.NumNextInitializedTicksResponse{LiquidityDepths: liquidityDepths, CurrentLiquidity: pool.GetLiquidity(), CurrentTick: pool.GetCurrentTick()}, nil
}
Loading

0 comments on commit 0f04b1b

Please sign in to comment.