Skip to content

Commit

Permalink
Merge pull request #180 from crescent-network/feat/public-position-id…
Browse files Browse the repository at this point in the history
…-query

feat: add position_id in public position query
  • Loading branch information
kingcre authored Aug 18, 2023
2 parents 92ccc70 + 467cf33 commit e68105d
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 79 deletions.
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10471,6 +10471,9 @@ paths:
format: uint64
liquidity:
type: string
position_id:
type: string
format: uint64
total_share:
type: object
properties:
Expand Down Expand Up @@ -10645,6 +10648,9 @@ paths:
format: uint64
liquidity:
type: string
position_id:
type: string
format: uint64
total_share:
type: object
properties:
Expand Down Expand Up @@ -19416,6 +19422,9 @@ definitions:
format: uint64
liquidity:
type: string
position_id:
type: string
format: uint64
total_share:
type: object
properties:
Expand Down Expand Up @@ -19550,6 +19559,9 @@ definitions:
format: uint64
liquidity:
type: string
position_id:
type: string
format: uint64
total_share:
type: object
properties:
Expand Down Expand Up @@ -19605,6 +19617,9 @@ definitions:
format: uint64
liquidity:
type: string
position_id:
type: string
format: uint64
total_share:
type: object
properties:
Expand Down
3 changes: 2 additions & 1 deletion proto/crescent/liquidamm/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,6 @@ message PublicPositionResponse {
uint64 last_rewards_auction_id = 8;
string liquidity = 9
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin total_share = 10 [(gogoproto.nullable) = false];
uint64 position_id = 10; // underlying x/amm position's id
cosmos.base.v1beta1.Coin total_share = 11 [(gogoproto.nullable) = false];
}
10 changes: 7 additions & 3 deletions x/liquidamm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ func (k Querier) PublicPositions(c context.Context, req *types.QueryPublicPositi
var publicPositions []types.PublicPositionResponse
pageRes, err := query.Paginate(publicPositionStore, req.Pagination, func(key, value []byte) error {
publicPosition := publicPositionGetter(key, value)
position, found := k.GetAMMPosition(ctx, publicPosition)
ammPosition, found := k.GetAMMPosition(ctx, publicPosition)
if !found {
position.Liquidity = utils.ZeroInt
ammPosition.Liquidity = utils.ZeroInt
ammPosition.Id = 0
}
shareDenom := types.ShareDenom(publicPosition.Id)
publicPositions = append(publicPositions, types.PublicPositionResponse{
Expand All @@ -84,8 +85,9 @@ func (k Querier) PublicPositions(c context.Context, req *types.QueryPublicPositi
MinBidAmount: publicPosition.MinBidAmount,
FeeRate: publicPosition.FeeRate,
LastRewardsAuctionId: publicPosition.LastRewardsAuctionId,
Liquidity: position.Liquidity,
Liquidity: ammPosition.Liquidity,
TotalShare: k.bankKeeper.GetSupply(ctx, shareDenom),
PositionId: ammPosition.Id,
})
return nil
})
Expand Down Expand Up @@ -116,6 +118,7 @@ func (k Querier) PublicPosition(c context.Context, req *types.QueryPublicPositio
ammPosition, found := k.GetAMMPosition(ctx, publicPosition)
if !found { // sanity check
ammPosition.Liquidity = utils.ZeroInt
ammPosition.Id = 0
}
shareDenom := types.ShareDenom(publicPosition.Id)
resp := types.PublicPositionResponse{
Expand All @@ -129,6 +132,7 @@ func (k Querier) PublicPosition(c context.Context, req *types.QueryPublicPositio
LastRewardsAuctionId: publicPosition.LastRewardsAuctionId,
Liquidity: ammPosition.Liquidity,
TotalShare: k.bankKeeper.GetSupply(ctx, shareDenom),
PositionId: ammPosition.Id,
}
return &types.QueryPublicPositionResponse{PublicPosition: resp}, nil
}
Expand Down
13 changes: 13 additions & 0 deletions x/liquidamm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ func (s *KeeperTestSuite) TestQueryPublicPosition() {
s.App.BankKeeper.GetSupply(s.Ctx, types.ShareDenom(publicPosition.Id)),
publicPosition.TotalShare)
s.Require().Equal(sdk.NewInt(43138144377), publicPosition.Liquidity)
s.Require().Equal(uint64(2), publicPosition.PositionId)
},
},
{
"no amm position",
&types.QueryPublicPositionRequest{
PublicPositionId: 2,
},
"",
func(resp *types.QueryPublicPositionResponse) {
publicPosition := resp.PublicPosition
s.Require().Equal(uint64(2), publicPosition.Id)
s.Require().Equal(uint64(0), publicPosition.PositionId)
},
},
} {
Expand Down
Loading

0 comments on commit e68105d

Please sign in to comment.