diff --git a/CHANGELOG.md b/CHANGELOG.md index cc7fc9e768..b82735899a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - [11268](https://github.com/vegaprotocol/vega/issues/11268) - Include derived parties vesting stats API - [11266](https://github.com/vegaprotocol/vega/issues/11266) - Include derived parties rewards API - [11357](https://github.com/vegaprotocol/vega/issues/11357) - Support historical game scores +- [11023](https://github.com/vegaprotocol/vega/issues/11023) - Add proposed fees to `vAMM` data. ### 🐛 Fixes diff --git a/datanode/entities/amm_pool.go b/datanode/entities/amm_pool.go index 462efae8ba..f8596cb81a 100644 --- a/datanode/entities/amm_pool.go +++ b/datanode/entities/amm_pool.go @@ -62,7 +62,7 @@ func AMMPoolFromProto(pool *eventspb.AMM, vegaTime time.Time) (AMMPool, error) { parametersBase, commitment num.Decimal parametersLowerBound, - parametersUpperBound *num.Decimal + parametersUpperBound, fee *num.Decimal err error ) partyID := PartyID(pool.PartyId) @@ -118,9 +118,12 @@ func AMMPoolFromProto(pool *eventspb.AMM, vegaTime time.Time) (AMMPool, error) { upperLeverage = &v } - fee, err := num.DecimalFromString(pool.ProposedFee) - if err != nil { - return AMMPool{}, err + if len(pool.ProposedFee) > 0 { + fd, err := num.DecimalFromString(pool.ProposedFee) + if err != nil { + return AMMPool{}, err + } + fee = &fd } return AMMPool{ @@ -136,7 +139,7 @@ func AMMPoolFromProto(pool *eventspb.AMM, vegaTime time.Time) (AMMPool, error) { ParametersUpperBound: parametersUpperBound, ParametersLeverageAtLowerBound: lowerLeverage, ParametersLeverageAtUpperBound: upperLeverage, - ProposedFee: &fee, + ProposedFee: fee, CreatedAt: vegaTime, LastUpdated: vegaTime, }, nil diff --git a/datanode/gateway/graphql/generated.go b/datanode/gateway/graphql/generated.go index b3d2cef3b7..6fb27be222 100644 --- a/datanode/gateway/graphql/generated.go +++ b/datanode/gateway/graphql/generated.go @@ -204,6 +204,7 @@ type ComplexityRoot struct { MarketId func(childComplexity int) int Parameters func(childComplexity int) int PartyId func(childComplexity int) int + ProposedFee func(childComplexity int) int Status func(childComplexity int) int StatusReason func(childComplexity int) int } @@ -4085,6 +4086,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.AMM.PartyId(childComplexity), true + case "AMM.proposedFee": + if e.complexity.AMM.ProposedFee == nil { + break + } + + return e.complexity.AMM.ProposedFee(childComplexity), true + case "AMM.status": if e.complexity.AMM.Status == nil { break @@ -20994,6 +21002,47 @@ func (ec *executionContext) fieldContext_AMM_statusReason(ctx context.Context, f return fc, nil } +func (ec *executionContext) _AMM_proposedFee(ctx context.Context, field graphql.CollectedField, obj *v1.AMM) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_AMM_proposedFee(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ProposedFee, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalOString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_AMM_proposedFee(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "AMM", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _AMMConnection_edges(ctx context.Context, field graphql.CollectedField, obj *v2.AMMConnection) (ret graphql.Marshaler) { fc, err := ec.fieldContext_AMMConnection_edges(ctx, field) if err != nil { @@ -21147,6 +21196,8 @@ func (ec *executionContext) fieldContext_AMMEdge_node(ctx context.Context, field return ec.fieldContext_AMM_status(ctx, field) case "statusReason": return ec.fieldContext_AMM_statusReason(ctx, field) + case "proposedFee": + return ec.fieldContext_AMM_proposedFee(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type AMM", field.Name) }, @@ -109242,6 +109293,8 @@ func (ec *executionContext) _AMM(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { out.Invalids++ } + case "proposedFee": + out.Values[i] = ec._AMM_proposedFee(ctx, field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } diff --git a/datanode/gateway/graphql/schema.graphql b/datanode/gateway/graphql/schema.graphql index 3c712af487..2b913578f8 100644 --- a/datanode/gateway/graphql/schema.graphql +++ b/datanode/gateway/graphql/schema.graphql @@ -7593,6 +7593,8 @@ type AMM { status: AMMStatus! "Reason for status if applicable" statusReason: AMMStatusReason! + "Proposed fee" + proposedFee: String } type ConcentratedLiquidityParameters { diff --git a/datanode/networkhistory/service_test.go b/datanode/networkhistory/service_test.go index 27192f8df4..2dd1b4db4d 100644 --- a/datanode/networkhistory/service_test.go +++ b/datanode/networkhistory/service_test.go @@ -379,12 +379,12 @@ func TestMain(t *testing.M) { log.Infof("%s", goldenSourceHistorySegment[4000].HistorySegmentID) log.Infof("%s", goldenSourceHistorySegment[5000].HistorySegmentID) - panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[1000].HistorySegmentID, "Qmf5QzhfokNqFE7N5Kf1oUmrzA94tTJNRWxB9ULShf1uzV", snapshots) - panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[2000].HistorySegmentID, "QmbsusmxWeUxCHdJRznLbtcevgKhF4dkvL9yFnhpJS3wQa", snapshots) - panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[2500].HistorySegmentID, "QmPfUnXkuBzmMjB2rcdtGMNhdd6mc3cvYMfS9rnMXjfu6L", snapshots) - panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[3000].HistorySegmentID, "QmRwtm3pUuUYG69tmbssFkYd2DafLELBeDfxuEjqjmXct8", snapshots) - panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[4000].HistorySegmentID, "QmQmC4xrdSJMiJ9MLgWdU1mptVv9TdSsYyosusd8dCt8A4", snapshots) - panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[5000].HistorySegmentID, "QmU3zDAHiQYWLyeYzwwCAynoh8A7g38ZaLpdV2h5pgkuL5", snapshots) + panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[1000].HistorySegmentID, "QmcnPQ9EtzgCBpeJ54ztxw6dkS8baWkndFqayQSAvvreYR", snapshots) + panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[2000].HistorySegmentID, "QmNw9naAXcxgXPxiMNih6ciUoH6i6kdE4Kop42B4b5VXnH", snapshots) + panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[2500].HistorySegmentID, "QmTn7YCSP5ZPBQNQHXroFatrKMuHshdUP8PdxRXPoLw74D", snapshots) + panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[3000].HistorySegmentID, "QmT2KLMWgezCczmcBkc1yXn3bgs7mBZWeTBARsAtJxFAVA", snapshots) + panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[4000].HistorySegmentID, "QmP9FKxEewC98C4YVhAmgJCxLeK49cLSPnve3Nrykz4efp", snapshots) + panicIfHistorySegmentIdsNotEqual(goldenSourceHistorySegment[5000].HistorySegmentID, "QmaPTyvUKeLBaASEXXbpFvzpkaHpZKTpiLEu6zfax1Yo8L", snapshots) }, postgresRuntimePath, sqlFs) if exitCode != 0 { diff --git a/datanode/sqlstore/amm_pool.go b/datanode/sqlstore/amm_pool.go index 0ff987a448..9d83625390 100644 --- a/datanode/sqlstore/amm_pool.go +++ b/datanode/sqlstore/amm_pool.go @@ -51,7 +51,7 @@ insert into amms(party_id, market_id, id, amm_party_id, commitment, status, status_reason, parameters_base, parameters_lower_bound, parameters_upper_bound, parameters_leverage_at_lower_bound, parameters_leverage_at_upper_bound, -created_at, last_updated) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) +created_at, last_updated, proposed_fee) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) on conflict (party_id, market_id, id, amm_party_id) do update set commitment=excluded.commitment, status=excluded.status, @@ -61,7 +61,8 @@ on conflict (party_id, market_id, id, amm_party_id) do update set parameters_upper_bound=excluded.parameters_upper_bound, parameters_leverage_at_lower_bound=excluded.parameters_leverage_at_lower_bound, parameters_leverage_at_upper_bound=excluded.parameters_leverage_at_upper_bound, - last_updated=excluded.last_updated;`, + last_updated=excluded.last_updated, + proposed_fee=excluded.proposed_fee;`, pool.PartyID, pool.MarketID, pool.ID, @@ -76,6 +77,7 @@ on conflict (party_id, market_id, id, amm_party_id) do update set pool.ParametersLeverageAtUpperBound, pool.CreatedAt, pool.LastUpdated, + pool.ProposedFee, ); err != nil { return fmt.Errorf("could not upsert AMM Pool: %w", err) } diff --git a/datanode/sqlstore/migrations/0113_add_proposed_fee.sql b/datanode/sqlstore/migrations/0113_add_proposed_fee.sql new file mode 100644 index 0000000000..f143fb8926 --- /dev/null +++ b/datanode/sqlstore/migrations/0113_add_proposed_fee.sql @@ -0,0 +1,7 @@ +-- +goose Up + +ALTER TABLE amms ADD COLUMN IF NOT EXISTS proposed_fee numeric; + +-- +goose Down + +ALTER TABLE amms DROP COLUMN IF EXISTS proposed_fee;