Skip to content

Commit

Permalink
feat: add proposed fee to event
Browse files Browse the repository at this point in the history
Signed-off-by: Elias Van Ootegem <[email protected]>
  • Loading branch information
EVODelavega committed Jun 14, 2024
1 parent 70ae513 commit 8867cc7
Show file tree
Hide file tree
Showing 6 changed files with 1,954 additions and 1,921 deletions.
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
12 changes: 12 additions & 0 deletions 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 Down Expand Up @@ -117,6 +118,11 @@ func AMMPoolFromProto(pool *eventspb.AMM, vegaTime time.Time) (AMMPool, error) {
upperLeverage = &v
}

fee, err := num.DecimalFromString(pool.ProposedFee)
if err != nil {
return AMMPool{}, err
}

return AMMPool{
PartyID: partyID,
MarketID: marketID,
Expand All @@ -130,13 +136,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 +161,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 +173,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
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 8867cc7

Please sign in to comment.