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

Query Settled participations #314

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ replace (
// use cosmos fork of keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0

github.com/cosmos/cosmos-sdk => github.com/sge-network/cosmos-sdk v0.46.17-0.20240116162805-4d37df374208
github.com/cosmos/cosmos-sdk => github.com/sge-network/cosmos-sdk v0.46.17-0.20240223100624-2a2661276cb4
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0
// use cosmos-compatible protobufs
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,8 @@ github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KR
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sge-network/cosmos-sdk v0.46.17-0.20240116162805-4d37df374208 h1:ZnS9z0KbYTgGwKB9Oy3pT6k7Nvd0EoVP2EBvKCTNFKo=
github.com/sge-network/cosmos-sdk v0.46.17-0.20240116162805-4d37df374208/go.mod h1:05U50tAsOzQ8JOAePshJCbJQw5ib1YJR6IXcqyVI1Xg=
github.com/sge-network/cosmos-sdk v0.46.17-0.20240223100624-2a2661276cb4 h1:HaHBgOxHd0mvl9Y07qujdnwtjcRweJsktbNPPy6LlwQ=
github.com/sge-network/cosmos-sdk v0.46.17-0.20240223100624-2a2661276cb4/go.mod h1:05U50tAsOzQ8JOAePshJCbJQw5ib1YJR6IXcqyVI1Xg=
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c h1:W65qqJCIOVP4jpqPQ0YvHYKwcMEMVWIzWC5iNQQfBTU=
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c/go.mod h1:/PevMnwAxekIXwN8qQyfc5gl2NlkB3CQlkizAbOkeBs=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
Expand Down
24 changes: 22 additions & 2 deletions proto/sge/orderbook/participation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ message OrderBookParticipation {
// is_settled represents if the participation is settled or not.
bool is_settled = 14 [ (gogoproto.moretags) = "yaml:\"is_settled\"" ];

// returned_amount is the total returned amount to the user's account including reimbursed fees.
// returned_amount is the total returned amount to the user's account
// including reimbursed fees.
string returned_amount = 15 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"returned_amount\""
];

// reimbursed_fee is the fee reimbursed because of reasons such as market calcellation.
// reimbursed_fee is the fee reimbursed because of reasons such as market
// calcellation.
string reimbursed_fee = 16 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
Expand Down Expand Up @@ -136,3 +138,21 @@ message ParticipationBetPair {
json_name = "bet_uid"
];
}

// SettledOrderbookParticipation is the type for a settled orderbook
// participation.
message SettledOrderbookParticipation {
// index is the index of the participation in the participation queue.
uint64 index = 1 [ (gogoproto.moretags) = "yaml:\"index\"" ];

// order_book_uid is the unique identifier corresponding to the order book.
string order_book_uid = 2 [
(gogoproto.customname) = "OrderBookUID",
(gogoproto.jsontag) = "order_book_uid",
json_name = "order_book_uid"
];

// participant_address is the bech32-encoded address of the participant.
string participant_address = 3
[ (gogoproto.moretags) = "yaml:\"participant_address\"" ];
}
23 changes: 23 additions & 0 deletions proto/sge/orderbook/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ service Query {
"/sge/orderbook/{order_book_uid}/participations/"
"{participation_index}/fulfilled_bets";
}

// Queries list of settled Orderbook Participation items of a certain height.
rpc SettledOrderbookParticipationsOfHeight(
QuerySettledOrderBookParticipationsOfHeightRequest)
returns (QuerySettledOrderbookParticipationsOfHeightResponse) {
option (google.api.http).get =
"/sge/orderbook/participations/settled/{block_height}";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method
Expand Down Expand Up @@ -304,3 +312,18 @@ message QueryParticipationFulfilledBetsResponse {
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QuerySettledOrderBookParticipationsOfHeightRequest is the request type for
// the settled orderbook participations of a certain height list query.
message QuerySettledOrderBookParticipationsOfHeightRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
int64 block_height = 2;
}

// QuerySettledOrderbookParticipationsOfHeightResponse is the response type for
// the settled orderbook participations of a certain height list query.
message QuerySettledOrderbookParticipationsOfHeightResponse {
repeated OrderBookParticipation participations = 1
[ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
2 changes: 1 addition & 1 deletion proto/sge/reward/authz.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ message UpdateCampaignAuthorization {
];
}

// WithdrawCampaignAuthorization allows the grantee to withdraw remaining
// WithdrawCampaignAuthorization allows the grantee to withdraw remaining
// pool balance of the campaign from the granter's account.
message WithdrawCampaignAuthorization {}
45 changes: 45 additions & 0 deletions x/orderbook/keeper/grpc_query_participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,48 @@ func (k Keeper) OrderBookParticipations(
Pagination: pageRes,
}, nil
}

// SettledOrderbookParticipationsOfHeight returns settled orderbook participations of a certain height
func (k Keeper) SettledOrderbookParticipationsOfHeight(
c context.Context,
req *types.QuerySettledOrderBookParticipationsOfHeightRequest,
) (*types.QuerySettledOrderBookParticipationsOfHeightResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, consts.ErrTextInvalidRequest)
}

var orderbookParticipations []types.OrderBookParticipation
ctx := sdk.UnwrapSDKContext(c)

settledOrderbookParticipationStore := prefix.NewStore(
ctx.KVStore(k.storeKey),
types.SettledOrderbookParticipationListOfBlockHeightPrefix(req.BlockHeight),
)

pageRes, err := query.Paginate(
settledOrderbookParticipationStore,
req.Pagination,
func(key []byte, value []byte) error {
var settledOrderbookParticipation types.SettledOrderbookParticipation
if err := k.cdc.Unmarshal(value, &settledOrderbookParticipation); err != nil {
return err
}

orderBookParticipation, found := k.GetOrderBookParticipation(
ctx,
settledOrderbookParticipation.OrderBookUID,
settledOrderbookParticipation.Index,
)
if found {
orderbookParticipations = append(orderbookParticipations, orderBookParticipation)
}

return nil
},
)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &types.QuerySettledOrderBookParticipationsOfHeightResponse{Participations: orderbookParticipations, Pagination: pageRes}, nil
}
8 changes: 8 additions & 0 deletions x/orderbook/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var (
0x07,
} // prefix for keys that store book participation and bet pairs
FeeGrantPrefix = []byte{0x08} // prefix for keys that store fee grants
// SettledOrderbookParticipationListPrefix is the prefix to retrieve all settled orderbook participations
SettledOrderbookParticipationListPrefix = []byte{0x09}
)

// GetOrderBookKey returns the bytes of an book key
Expand Down Expand Up @@ -109,3 +111,9 @@ func GetParticipationBetPairKey(bookUID string, bookParticipationIndex, betID ui
GetParticipationByIndexKey(bookUID, bookParticipationIndex),
utils.Uint64ToBytes(betID)...)
}

// SettledOrderbookParticipationListOfBlockHeightPrefix returns prefix of
// settled orderbook participation list on a certain block height.
func SettledOrderbookParticipationListOfBlockHeightPrefix(blockHeight int64) []byte {
return append(SettledOrderbookParticipationListPrefix, utils.Int64ToBytes(blockHeight)...)
}
Loading
Loading