Skip to content

Commit

Permalink
chore: cl unbonding positions query (#5684)
Browse files Browse the repository at this point in the history
* cl unbonding positions query

* cl unbonding positions query

* regen proto

* add basic test

* chore: sf undelegating / delegated cl queries (#5691)

* undelegating / delegated cl queries

* correct comment

* remove switch and add errors.Is

* Update proto/osmosis/superfluid/query.proto

Co-authored-by: Jon Ator <[email protected]>

* Update proto/osmosis/superfluid/query.proto

Co-authored-by: Jon Ator <[email protected]>

* rename to delegate in place of bond

* fix errors Is

---------

Co-authored-by: Jon Ator <[email protected]>

* remove switch statement

* add position id to error

* add synth lock to q

* regen proto

---------

Co-authored-by: Jon Ator <[email protected]>
  • Loading branch information
czarcas7ic and jonator authored Jul 2, 2023
1 parent e44b5cd commit f9b3cc1
Show file tree
Hide file tree
Showing 17 changed files with 2,072 additions and 550 deletions.
6 changes: 6 additions & 0 deletions proto/osmosis/concentrated-liquidity/position.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "osmosis/lockup/lock.proto";

option go_package = "github.com/osmosis-labs/osmosis/v16/x/concentrated-liquidity/model";

Expand Down Expand Up @@ -63,3 +64,8 @@ message FullPositionBreakdown {
(gogoproto.nullable) = false
];
}

message PositionWithPeriodLock {
Position position = 1 [ (gogoproto.nullable) = false ];
osmosis.lockup.PeriodLock locks = 2 [ (gogoproto.nullable) = false ];
}
19 changes: 19 additions & 0 deletions proto/osmosis/concentrated-liquidity/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ service Query {
"{concentrated_pool_id}";
}

// UserUnbondingPositions returns the position and lock info of unbonding
// positions of the given address.
rpc UserUnbondingPositions(UserUnbondingPositionsRequest)
returns (UserUnbondingPositionsResponse) {
option (google.api.http).get = "/osmosis/concentratedliquidity/v1beta1/"
"user_unbonding_positions/"
"{address}";
}

// GetTotalLiquidity returns total liquidity across all cl pools.
rpc GetTotalLiquidity(GetTotalLiquidityRequest)
returns (GetTotalLiquidityResponse) {
Expand Down Expand Up @@ -288,6 +297,16 @@ message CFMMPoolIdLinkFromConcentratedPoolIdResponse {
uint64 cfmm_pool_id = 1 [ (gogoproto.moretags) = "yaml:\"cfmm_pool_id\"" ];
}

//=============================== UserUnbondingPositions
message UserUnbondingPositionsRequest {
string address = 1 [ (gogoproto.moretags) = "yaml:\"address\"" ];
}

message UserUnbondingPositionsResponse {
repeated PositionWithPeriodLock positions_with_period_lock = 1
[ (gogoproto.nullable) = false ];
}

//=============================== GetTotalLiquidity
message GetTotalLiquidityRequest {}
message GetTotalLiquidityResponse {
Expand Down
5 changes: 5 additions & 0 deletions proto/osmosis/concentrated-liquidity/query.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ queries:
query_func: "k.CFMMPoolIdLinkFromConcentratedPoolId"
cli:
cmd: "CFMMPoolIdLinkFromConcentratedPoolId"
UserUnbondingPositions:
proto_wrapper:
query_func: "k.UserUnbondingPositions"
cli:
cmd: "UserUnbondingPositions"
GetTotalLiquidity:
proto_wrapper:
query_func: "k.GetTotalLiquidity"
Expand Down
35 changes: 24 additions & 11 deletions proto/osmosis/superfluid/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,20 @@ service Query {
"unpool_whitelist";
}

rpc UserSuperfluidPositionsPerConcentratedPoolBreakdown(
UserSuperfluidPositionsPerConcentratedPoolBreakdownRequest)
returns (UserSuperfluidPositionsPerConcentratedPoolBreakdownResponse) {
rpc UserConcentratedSuperfluidPositionsDelegated(
UserConcentratedSuperfluidPositionsDelegatedRequest)
returns (UserConcentratedSuperfluidPositionsDelegatedResponse) {
option (google.api.http).get = "/osmosis/superfluid/v1beta1/"
"user_superfluid_positions_per_pool/"
"{delegator_address}/{concentrated_pool_id}";
"account_delegated_cl_positions/"
"{delegator_address}";
}

rpc UserConcentratedSuperfluidPositionsUndelegating(
UserConcentratedSuperfluidPositionsUndelegatingRequest)
returns (UserConcentratedSuperfluidPositionsUndelegatingResponse) {
option (google.api.http).get = "/osmosis/superfluid/v1beta1/"
"account_undelegating_cl_positions/"
"{delegator_address}";
}
}

Expand Down Expand Up @@ -291,15 +299,20 @@ message QueryUnpoolWhitelistRequest {}

message QueryUnpoolWhitelistResponse { repeated uint64 pool_ids = 1; }

//===============================
// UserSuperfluidPositionsPerConcentratedPoolBreakdown
message UserSuperfluidPositionsPerConcentratedPoolBreakdownRequest {
message UserConcentratedSuperfluidPositionsDelegatedRequest {
string delegator_address = 1;
}

message UserConcentratedSuperfluidPositionsDelegatedResponse {
repeated ConcentratedPoolUserPositionRecord cl_pool_user_position_records = 1
[ (gogoproto.nullable) = false ];
}

message UserConcentratedSuperfluidPositionsUndelegatingRequest {
string delegator_address = 1;
uint64 concentrated_pool_id = 2
[ (gogoproto.moretags) = "yaml:\"concentrated_pool_id\"" ];
}

message UserSuperfluidPositionsPerConcentratedPoolBreakdownResponse {
message UserConcentratedSuperfluidPositionsUndelegatingResponse {
repeated ConcentratedPoolUserPositionRecord cl_pool_user_position_records = 1
[ (gogoproto.nullable) = false ];
}
7 changes: 5 additions & 2 deletions proto/osmosis/superfluid/superfluid.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "gogoproto/gogo.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/base/v1beta1/coin.proto";
import "osmosis/lockup/lock.proto";

option go_package = "github.com/osmosis-labs/osmosis/v16/x/superfluid/types";

Expand Down Expand Up @@ -86,10 +87,12 @@ message ConcentratedPoolUserPositionRecord {
string validator_address = 1;
uint64 position_id = 2;
uint64 lock_id = 3;
cosmos.base.v1beta1.Coin delegation_amount = 4 [
osmosis.lockup.SyntheticLock synthetic_lock = 4
[ (gogoproto.nullable) = false ];
cosmos.base.v1beta1.Coin delegation_amount = 5 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
cosmos.base.v1beta1.Coin equivalent_staked_amount = 5
cosmos.base.v1beta1.Coin equivalent_staked_amount = 6
[ (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin" ];
}
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 @@ -20,6 +20,16 @@ type Querier struct {

var _ queryproto.QueryServer = Querier{}

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

func (q Querier) UserPositions(grpcCtx context.Context,
req *queryproto.UserPositionsRequest,
) (*queryproto.UserPositionsResponse, error) {
Expand Down
13 changes: 13 additions & 0 deletions x/concentrated-liquidity/client/query_proto_wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,19 @@ func (q Querier) CFMMPoolIdLinkFromConcentratedPoolId(ctx sdk.Context, req clque
}, nil
}

// UserUnbodingPositions returns all the unbonding concentrated liquidity positions along with their respective period lock.
func (q Querier) UserUnbondingPositions(ctx sdk.Context, req clquery.UserUnbondingPositionsRequest) (*clquery.UserUnbondingPositionsResponse, error) {
sdkAddr, err := sdk.AccAddressFromBech32(req.Address)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

cfmmPoolId, err := q.Keeper.GetUserUnbondingPositions(ctx, sdkAddr)
return &clquery.UserUnbondingPositionsResponse{
PositionsWithPeriodLock: cfmmPoolId,
}, nil
}

// GetTotalLiquidity returns the total liquidity across all concentrated liquidity pools.
func (q Querier) GetTotalLiquidity(ctx sdk.Context, req clquery.GetTotalLiquidityRequest) (*clquery.GetTotalLiquidityResponse, error) {
totalLiquidity, err := q.Keeper.GetTotalLiquidity(ctx)
Expand Down
Loading

0 comments on commit f9b3cc1

Please sign in to comment.