Skip to content

Commit

Permalink
Merge branch 'develop' into bb_auctions
Browse files Browse the repository at this point in the history
  • Loading branch information
ze97286 authored Sep 5, 2024
2 parents d4194f8 + c796944 commit ba6b23e
Show file tree
Hide file tree
Showing 6 changed files with 4,619 additions and 4,570 deletions.
16 changes: 16 additions & 0 deletions datanode/api/trading_data_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,22 @@ func (t *TradingDataServiceV2) ListAllPositions(ctx context.Context, req *v2.Lis
return nil, formatE(err, errors.New("one or more party id is invalid"))
}
req.Filter.PartyIds = partyIDs

// check for derived parties
if ptr.UnBox(req.Filter.IncludeDerivedParties) {
if len(partyIDs) == 0 {
return nil, formatE(newInvalidArgumentError("includeDerivedParties requires a partyId"))
}

derivedParties, err := t.AMMPoolService.GetSubKeysForParties(ctx, partyIDs, marketIDs)
if err != nil {
return nil, formatE(ErrPositionServiceGetByParty, err)
}
slices.Sort(derivedParties)
partyIDs = append(partyIDs, derivedParties...)
}

req.Filter.PartyIds = partyIDs
}

pagination, err := entities.CursorPaginationFromProto(req.Pagination)
Expand Down
9 changes: 8 additions & 1 deletion datanode/gateway/graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions datanode/gateway/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6340,6 +6340,7 @@ type PositionEdge {
input PositionsFilter {
partyIds: [ID!]
marketIds: [ID!]
includeDerivedParties: Boolean
}

"Connection type for retrieving cursor-based paginated position information"
Expand Down
19 changes: 13 additions & 6 deletions datanode/sqlstore/amm_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"code.vegaprotocol.io/vega/datanode/entities"
"code.vegaprotocol.io/vega/datanode/metrics"
"code.vegaprotocol.io/vega/libs/ptr"
v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2"

"github.com/georgysavva/scany/pgxscan"
Expand Down Expand Up @@ -165,12 +166,12 @@ func (p *AMMPools) GetSubKeysForParties(ctx context.Context, partyIDs []string,
}
parties := strings.Builder{}
args := make([]any, 0, len(partyIDs)+len(marketIDs))
query := `SELECT amm_party_id FROM amms WHERE "`
query := `SELECT amm_party_id FROM amms WHERE `
for i, party := range partyIDs {
if i > 0 {
parties.WriteString(",")
}
parties.WriteString(nextBindVar(&args, party))
parties.WriteString(nextBindVar(&args, ptr.From(entities.PartyID(party))))
}
query = fmt.Sprintf(`%s party_id IN (%s)`, query, parties.String())
if len(marketIDs) > 0 {
Expand All @@ -179,16 +180,22 @@ func (p *AMMPools) GetSubKeysForParties(ctx context.Context, partyIDs []string,
if i > 0 {
markets.WriteString(",")
}
markets.WriteString(nextBindVar(&args, mID))

markets.WriteString(nextBindVar(&args, ptr.From(entities.MarketID(mID))))
}
query = fmt.Sprintf("%s AND market_id IN(%s)", query, markets.String())
query = fmt.Sprintf("%s AND market_id IN (%s)", query, markets.String())
}

subKeys := []string{}
subKeys := []entities.PartyID{}
if err := pgxscan.Select(ctx, p.ConnectionSource, &subKeys, query, args...); err != nil {
return nil, err
}
return subKeys, nil

res := make([]string, 0, len(subKeys))
for _, k := range subKeys {
res = append(res, k.String())
}
return res, nil
}

func (p *AMMPools) ListByPool(ctx context.Context, poolID entities.AMMPoolID, pagination entities.CursorPagination) ([]entities.AMMPool, entities.PageInfo, error) {
Expand Down
Loading

0 comments on commit ba6b23e

Please sign in to comment.