Skip to content

Commit

Permalink
Merge pull request #11382 from vegaprotocol/11023-amm-fees
Browse files Browse the repository at this point in the history
11023 amm fees
  • Loading branch information
EVODelavega authored Jun 14, 2024
2 parents 70ae513 + b40d2b6 commit 27235c0
Show file tree
Hide file tree
Showing 12 changed files with 2,031 additions and 1,930 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions core/events/amm_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func NewAMMPoolEvent(
p *types.ConcentratedLiquidityParameters,
status types.AMMPoolStatus,
statusReason types.AMMStatusReason,
fees num.Decimal,
) *AMMPool {
order := &AMMPool{
return &AMMPool{
Base: newBase(ctx, AMMPoolEvent),
pool: &eventspb.AMM{
Id: poolID,
Expand All @@ -47,10 +48,9 @@ func NewAMMPoolEvent(
Parameters: p.ToProtoEvent(),
Status: status,
StatusReason: statusReason,
ProposedFee: fees.String(),
},
}
// set to original order price
return order
}

func (p AMMPool) IsParty(id string) bool {
Expand Down
5 changes: 5 additions & 0 deletions core/execution/amm/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ func (e *Engine) Create(
ctx, submit.Party, e.marketID, subAccount, poolID,
submit.CommitmentAmount, submit.Parameters,
types.AMMPoolStatusRejected, types.AMMStatusReasonPartyAlreadyOwnsAPool,
submit.ProposedFee,
),
)

Expand All @@ -628,6 +629,7 @@ func (e *Engine) Create(
ctx, submit.Party, e.marketID, subAccount, poolID,
submit.CommitmentAmount, submit.Parameters,
types.AMMPoolStatusRejected, reason,
submit.ProposedFee,
),
)
return nil, err
Expand All @@ -640,6 +642,7 @@ func (e *Engine) Create(
ctx, submit.Party, e.marketID, subAccount, poolID,
submit.CommitmentAmount, submit.Parameters,
types.AMMPoolStatusRejected, types.AMMStatusReasonUnspecified,
submit.ProposedFee,
),
)

Expand Down Expand Up @@ -667,6 +670,7 @@ func (e *Engine) Create(
ctx, submit.Party, e.marketID, subAccount, poolID,
submit.CommitmentAmount, submit.Parameters,
types.AMMPoolStatusRejected, types.AMMStatusReasonCommitmentTooLow,
submit.ProposedFee,
),
)

Expand Down Expand Up @@ -801,6 +805,7 @@ func (e *Engine) sendUpdate(ctx context.Context, pool *Pool) {
ctx, pool.owner, e.marketID, pool.AMMParty, pool.ID,
pool.Commitment, pool.Parameters,
pool.status, types.AMMStatusReasonUnspecified,
pool.ProposedFee,
),
)
}
Expand Down
3 changes: 3 additions & 0 deletions core/execution/future/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -5446,6 +5446,7 @@ func (m *Market) SubmitAMM(ctx context.Context, submit *types.SubmitAMM, determi
ctx, pool.Owner(), m.GetID(), pool.AMMParty, pool.ID,
pool.CommitmentAmount(), pool.Parameters,
types.AMMPoolStatusRejected, types.AMMStatusReasonCannotRebase,
pool.ProposedFee,
),
)
return err
Expand All @@ -5459,6 +5460,7 @@ func (m *Market) SubmitAMM(ctx context.Context, submit *types.SubmitAMM, determi
ctx, submit.Party, m.GetID(), pool.AMMParty, pool.ID,
submit.CommitmentAmount, submit.Parameters,
types.AMMPoolStatusRejected, types.AMMStatusReasonCannotFillCommitment,
pool.ProposedFee,
),
)
return err
Expand All @@ -5483,6 +5485,7 @@ func (m *Market) SubmitAMM(ctx context.Context, submit *types.SubmitAMM, determi
ctx, submit.Party, m.GetID(), pool.AMMParty, pool.ID,
submit.CommitmentAmount, submit.Parameters,
types.AMMPoolStatusRejected, types.AMMStatusReasonCannotRebase,
pool.ProposedFee,
),
)
return err
Expand Down
17 changes: 16 additions & 1 deletion datanode/entities/amm_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type AMMPool struct {
ParametersUpperBound *num.Decimal
ParametersLeverageAtLowerBound *num.Decimal
ParametersLeverageAtUpperBound *num.Decimal
ProposedFee *num.Decimal
CreatedAt time.Time
LastUpdated time.Time
}
Expand All @@ -61,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)
Expand Down Expand Up @@ -117,6 +118,14 @@ func AMMPoolFromProto(pool *eventspb.AMM, vegaTime time.Time) (AMMPool, error) {
upperLeverage = &v
}

if len(pool.ProposedFee) > 0 {
fd, err := num.DecimalFromString(pool.ProposedFee)
if err != nil {
return AMMPool{}, err
}
fee = &fd
}

return AMMPool{
PartyID: partyID,
MarketID: marketID,
Expand All @@ -130,13 +139,15 @@ func AMMPoolFromProto(pool *eventspb.AMM, vegaTime time.Time) (AMMPool, error) {
ParametersUpperBound: parametersUpperBound,
ParametersLeverageAtLowerBound: lowerLeverage,
ParametersLeverageAtUpperBound: upperLeverage,
ProposedFee: fee,
CreatedAt: vegaTime,
LastUpdated: vegaTime,
}, nil
}

func (p AMMPool) ToProto() *eventspb.AMM {
var lowerBound, upperBound, lowerLeverage, upperLeverage *string
var fee string

if p.ParametersLowerBound != nil {
lowerBound = ptr.From(p.ParametersLowerBound.String())
Expand All @@ -153,6 +164,9 @@ func (p AMMPool) ToProto() *eventspb.AMM {
if p.ParametersLeverageAtUpperBound != nil {
upperLeverage = ptr.From(p.ParametersLeverageAtUpperBound.String())
}
if p.ProposedFee != nil {
fee = p.ProposedFee.String()
}

return &eventspb.AMM{
PartyId: p.PartyID.String(),
Expand All @@ -162,6 +176,7 @@ func (p AMMPool) ToProto() *eventspb.AMM {
Commitment: p.Commitment.String(),
Status: eventspb.AMM_Status(p.Status),
StatusReason: eventspb.AMM_StatusReason(p.StatusReason),
ProposedFee: fee,
Parameters: &eventspb.AMM_ConcentratedLiquidityParameters{
Base: p.ParametersBase.String(),
LowerBound: lowerBound,
Expand Down
53 changes: 53 additions & 0 deletions datanode/gateway/graphql/generated.go

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

2 changes: 2 additions & 0 deletions datanode/gateway/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7593,6 +7593,8 @@ type AMM {
status: AMMStatus!
"Reason for status if applicable"
statusReason: AMMStatusReason!
"Proposed fee"
proposedFee: String
}

type ConcentratedLiquidityParameters {
Expand Down
12 changes: 6 additions & 6 deletions datanode/networkhistory/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions datanode/sqlstore/amm_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down
7 changes: 7 additions & 0 deletions datanode/sqlstore/migrations/0113_add_proposed_fee.sql
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions protos/sources/vega/events/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ message AMM {
Status status = 7;
// Reason for the AMM's current status.
StatusReason status_reason = 8;
// Nominated liquidity fee factor, which is an input to the calculation of taker fees on the market.
string proposed_fee = 9;

enum Status {
STATUS_UNSPECIFIED = 0;
Expand Down
Loading

0 comments on commit 27235c0

Please sign in to comment.