Skip to content

Commit

Permalink
[1789]: Default the CommitmentSettlementFeeCalc endpoint to only retu…
Browse files Browse the repository at this point in the history
…rning the exchange fees, but allow the other fields to be populated if requested.
  • Loading branch information
SpicyLemon committed Jan 26, 2024
1 parent f6f1319 commit eeb3f93
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 126 deletions.
1 change: 1 addition & 0 deletions docs/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2943,6 +2943,7 @@ QueryCommitmentSettlementFeeCalcRequest is a request message for the CommitmentS
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `settlement` | [MsgMarketCommitmentSettleRequest](#provenance.exchange.v1.MsgMarketCommitmentSettleRequest) | | settlement is a market's commitment settlement request message. If no inputs are provided, only the to_fee_nav field will be populated in the response. |
| `include_breakdown_fields` | [bool](#bool) | | include_breakdown_fields controls the fields that are populated in the response. If false, only the exchange_fees field is populated. If true, all of the fields are populated as possible. If the settlement does not have any inputs, this field defaults to true. |



Expand Down
5 changes: 5 additions & 0 deletions proto/provenance/exchange/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ message QueryCommitmentSettlementFeeCalcRequest {
// settlement is a market's commitment settlement request message.
// If no inputs are provided, only the to_fee_nav field will be populated in the response.
MsgMarketCommitmentSettleRequest settlement = 1;
// include_breakdown_fields controls the fields that are populated in the response.
// If false, only the exchange_fees field is populated.
// If true, all of the fields are populated as possible.
// If the settlement does not have any inputs, this field defaults to true.
bool include_breakdown_fields = 2;
}

// QueryCommitmentSettlementFeeCalcResponse is a response message for the CommitmentSettlementFeeCalc query.
Expand Down
4 changes: 4 additions & 0 deletions x/exchange/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ func (k QueryServer) CommitmentSettlementFeeCalc(goCtx context.Context, req *exc
return nil, status.Error(codes.InvalidArgument, err.Error())
}

if !req.IncludeBreakdownFields && len(req.Settlement.Inputs) > 0 {
resp = &exchange.QueryCommitmentSettlementFeeCalcResponse{ExchangeFees: resp.ExchangeFees}
}

return resp, nil
}

Expand Down
50 changes: 50 additions & 0 deletions x/exchange/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3948,6 +3948,7 @@ func (s *TestSuite) TestQueryServer_CommitmentSettlementFeeCalc() {
{Assets: s.coin("1cherry"), Price: s.coin("20nhash")},
},
},
IncludeBreakdownFields: true,
},
expResp: &exchange.QueryCommitmentSettlementFeeCalcResponse{
InputTotal: s.coins("15apple"),
Expand All @@ -3957,6 +3958,28 @@ func (s *TestSuite) TestQueryServer_CommitmentSettlementFeeCalc() {
ToFeeNav: &exchange.NetAssetPrice{Assets: s.coin("1cherry"), Price: s.coin("20nhash")},
},
},
{
name: "some inputs and navs: just exchange fees",
setup: func() {
s.requireCreateMarket(exchange.Market{
MarketId: 2,
CommitmentSettlementBips: 50,
IntermediaryDenom: "cherry",
})
},
req: &exchange.QueryCommitmentSettlementFeeCalcRequest{
Settlement: &exchange.MsgMarketCommitmentSettleRequest{
MarketId: 2,
Inputs: []exchange.AccountAmount{{Account: s.addr1.String(), Amount: s.coins("15apple")}},
Outputs: []exchange.AccountAmount{{Account: s.addr2.String(), Amount: s.coins("15apple")}},
Navs: []exchange.NetAssetPrice{
{Assets: s.coin("1apple"), Price: s.coin("4cherry")},
{Assets: s.coin("1cherry"), Price: s.coin("20nhash")},
},
},
},
expResp: &exchange.QueryCommitmentSettlementFeeCalcResponse{ExchangeFees: s.coins("3nhash")},
},
{
name: "some inputs, navs from state",
setup: func() {
Expand All @@ -3980,6 +4003,7 @@ func (s *TestSuite) TestQueryServer_CommitmentSettlementFeeCalc() {
Inputs: []exchange.AccountAmount{{Account: s.addr1.String(), Amount: s.coins("15apple")}},
Outputs: []exchange.AccountAmount{{Account: s.addr2.String(), Amount: s.coins("15apple")}},
},
IncludeBreakdownFields: true,
},
expResp: &exchange.QueryCommitmentSettlementFeeCalcResponse{
InputTotal: s.coins("15apple"),
Expand All @@ -3989,6 +4013,32 @@ func (s *TestSuite) TestQueryServer_CommitmentSettlementFeeCalc() {
ToFeeNav: &exchange.NetAssetPrice{Assets: s.coin("1cherry"), Price: s.coin("20nhash")},
},
},
{
name: "some inputs, navs from state: just exchange fees",
setup: func() {
s.requireCreateMarket(exchange.Market{
MarketId: 2,
CommitmentSettlementBips: 50,
IntermediaryDenom: "cherry",
})
s.requireAddFinalizeAndActivateMarker(s.coin("1000000apple"), s.addr5)
s.requireAddFinalizeAndActivateMarker(s.coin("1000000cherry"), s.addr5)

appleMarker := s.requireGetMarker("apple")
cherryMarker := s.requireGetMarker("cherry")

s.requireSetNav(appleMarker, 1, "4cherry")
s.requireSetNav(cherryMarker, 1, "20nhash")
},
req: &exchange.QueryCommitmentSettlementFeeCalcRequest{
Settlement: &exchange.MsgMarketCommitmentSettleRequest{
MarketId: 2,
Inputs: []exchange.AccountAmount{{Account: s.addr1.String(), Amount: s.coins("15apple")}},
Outputs: []exchange.AccountAmount{{Account: s.addr2.String(), Amount: s.coins("15apple")}},
},
},
expResp: &exchange.QueryCommitmentSettlementFeeCalcResponse{ExchangeFees: s.coins("3nhash")},
},
}

for _, tc := range tests {
Expand Down
Loading

0 comments on commit eeb3f93

Please sign in to comment.