Skip to content

Commit

Permalink
Merge pull request #9575 from vegaprotocol/update-sla-stats
Browse files Browse the repository at this point in the history
Add new SLA stats
  • Loading branch information
jeremyletang authored Sep 27, 2023
2 parents 1fb26aa + 7341133 commit 2b4cf98
Show file tree
Hide file tree
Showing 13 changed files with 1,624 additions and 1,309 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@
- [9478](https://github.com/vegaprotocol/vega/issues/8764) - Add SLA statistics to market data and liquidity provision APIs.
- [9558](https://github.com/vegaprotocol/vega/issues/9558) - Feature tests for relative return metric transfers and reward
- [9559](https://github.com/vegaprotocol/vega/issues/9559) - Feature tests for return volatility metric transfers and reward
- [9564](https://github.com/vegaprotocol/vega/issues/9564) - Fix error message for too many staking tiers.
- [9564](https://github.com/vegaprotocol/vega/issues/9564) - Fix error message for too many staking tiers.
- [8421](https://github.com/vegaprotocol/vega/issues/8421) - Markets that spend too long in opening auction should be cancelled.
- [9575](https://github.com/vegaprotocol/vega/issues/9575) - Expand SLA statistics by required liquidity and notional volumes.

### 🐛 Fixes

Expand Down
3 changes: 3 additions & 0 deletions core/liquidity/v2/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ type slaPerformance struct {
lastEpochBondPenalty string
lastEpochFeePenalty string
lastEpochTimeBookFraction string
requiredLiquidity string
notionalVolumeBuys string
notionalVolumeSells string
}

type SlaPenalties struct {
Expand Down
8 changes: 8 additions & 0 deletions core/liquidity/v2/sla.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ func (e *Engine) doesLPMeetsCommitment(

requiredLiquidity := e.stakeToCcyVolume.Mul(lp.CommitmentAmount.ToDecimal())

// safe stats
e.slaPerformance[party].requiredLiquidity = requiredLiquidity.String()
e.slaPerformance[party].notionalVolumeBuys = notionalVolumeBuys.String()
e.slaPerformance[party].notionalVolumeSells = notionalVolumeSells.String()

return notionalVolumeBuys.GreaterThanOrEqual(requiredLiquidity) &&
notionalVolumeSells.GreaterThanOrEqual(requiredLiquidity)
}
Expand Down Expand Up @@ -256,6 +261,9 @@ func (e *Engine) LiquidityProviderSLAStats(now time.Time) []*types.LiquidityProv
LastEpochFeePenalty: commitment.lastEpochFeePenalty,
LastEpochBondPenalty: commitment.lastEpochBondPenalty,
HysteresisPeriodFeePenalties: hysteresisPeriodFeePenalties,
RequiredLiquidity: commitment.requiredLiquidity,
NotionalVolumeBuys: commitment.notionalVolumeBuys,
NotionalVolumeSells: commitment.notionalVolumeSells,
})
}

Expand Down
3 changes: 3 additions & 0 deletions core/liquidity/v2/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ func (e *snapshotV2) loadPerformances(performances *snapshotpb.LiquidityV2Perfor
lastEpochTimeBookFraction: partyPerformance.LastEpochFractionOfTimeOnBook,
lastEpochBondPenalty: partyPerformance.LastEpochBondPenalty,
lastEpochFeePenalty: partyPerformance.LastEpochFeePenalty,
requiredLiquidity: partyPerformance.RequiredLiquidity,
notionalVolumeBuys: partyPerformance.NotionalVolumeBuys,
notionalVolumeSells: partyPerformance.NotionalVolumeSells,
}
}

Expand Down
189 changes: 189 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.

3 changes: 3 additions & 0 deletions datanode/gateway/graphql/models.go

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

12 changes: 12 additions & 0 deletions datanode/gateway/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ type LiquidityProviderSLA {
lastEpochBondPenalty: String!
"Determines how the fee penalties from past epochs affect future fee revenue."
hysteresisPeriodFeePenalties: [String!]
"Represents the total amount of funds LP must supply. The amount to be supplied is in the market’s settlement currency, spread on both buy and sell sides of the order book within a defined range."
requiredLiquidity: String!
"Notional volume of orders within the range provided on the buy side of the book."
notionalVolumeBuys: String!
"Notional volume of orders within the range provided on the sell side of the book."
notionalVolumeSells: String!
}

"The SLA statistics for each liquidity provider"
Expand All @@ -412,6 +418,12 @@ type ObservableLiquidityProviderSLA {
lastEpochBondPenalty: String!
"Determines how the fee penalties from past epochs affect future fee revenue."
hysteresisPeriodFeePenalties: [String!]
"Represents the total amount of funds LP must supply. The amount to be supplied is in the market’s settlement currency, spread on both buy and sell sides of the order book within a defined range."
requiredLiquidity: String!
"Notional volume of orders within the range provided on the buy side of the book."
notionalVolumeBuys: String!
"Notional volume of orders within the range provided on the sell side of the book."
notionalVolumeSells: String!
}

"The liquidity commitments for this market"
Expand Down
13 changes: 11 additions & 2 deletions datanode/sqlstore/liquidity_provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ type LiquidityProviderSLA struct {
LastEpochFeePenalty string
LastEpochBondPenalty string
HysteresisPeriodFeePenalties []string
RequiredLiquidity string
NotionalVolumeBuys string
NotionalVolumeSells string
}

const (
Expand Down Expand Up @@ -222,6 +225,9 @@ func (lp *LiquidityProvision) ListProviders(ctx context.Context, partyID *entiti
LastEpochFeePenalty: sla.LastEpochFeePenalty,
LastEpochBondPenalty: sla.LastEpochBondPenalty,
HysteresisPeriodFeePenalties: sla.HysteresisPeriodFeePenalties,
RequiredLiquidity: sla.RequiredLiquidity,
NotionalVolumeBuys: sla.NotionalVolumeBuys,
NotionalVolumeSells: sla.NotionalVolumeSells,
}
}

Expand Down Expand Up @@ -284,6 +290,9 @@ select
coalesce(lpsla.sla ->> 'last_epoch_fraction_of_time_on_book', '') as last_epoch_fraction_of_time_on_book,
coalesce(lpsla.sla ->> 'last_epoch_fee_penalty', '') as last_epoch_fee_penalty,
coalesce(lpsla.sla ->> 'last_epoch_bond_penalty', '') as last_epoch_bond_penalty,
coalesce(lpsla.sla ->> 'required_liquidity', '') as required_liquidity,
coalesce(lpsla.sla ->> 'notional_volume_buys', '') as notional_volume_buys,
coalesce(lpsla.sla ->> 'notional_volume_sells', '') as notional_volume_sells,
lpsla.sla -> 'hysteresis_period_fee_penalties' as hysteresis_period_fee_penalties
from current_market_data cmd,
jsonb_array_elements(liquidity_provider_sla) with ordinality lpsla(sla, ordinality)
Expand All @@ -301,8 +310,8 @@ where liquidity_provider_sla != 'null' and liquidity_provider_sla is not null

// we join with the live liquidity providers table to make sure we are only returning data
// for liquidity providers that are currently active
query := fmt.Sprintf(`WITH liquidity_provider_sla(ordinality, market_id, party_id, current_epoch_fraction_of_time_on_book, last_epoch_fraction_of_time_on_book, last_epoch_fee_penalty, last_epoch_bond_penalty, hysteresis_period_fee_penalties) as (%s)
SELECT fs.ordinality, fs.market_id, fs.party_id, fs.current_epoch_fraction_of_time_on_book, fs.last_epoch_fraction_of_time_on_book, fs.last_epoch_fee_penalty, fs.last_epoch_bond_penalty, fs.hysteresis_period_fee_penalties
query := fmt.Sprintf(`WITH liquidity_provider_sla(ordinality, market_id, party_id, current_epoch_fraction_of_time_on_book, last_epoch_fraction_of_time_on_book, last_epoch_fee_penalty, last_epoch_bond_penalty, required_liquidity, notional_volume_buys, notional_volume_sells, hysteresis_period_fee_penalties) as (%s)
SELECT fs.ordinality, fs.market_id, fs.party_id, fs.current_epoch_fraction_of_time_on_book, fs.last_epoch_fraction_of_time_on_book, fs.last_epoch_fee_penalty, fs.last_epoch_bond_penalty, fs.required_liquidity, fs.notional_volume_buys, fs.notional_volume_sells, fs.hysteresis_period_fee_penalties
FROM liquidity_provider_sla fs
JOIN live_liquidity_provisions lps ON encode(lps.party_id, 'hex') = fs.party_id
AND lps.market_id = fs.market_id`, subQuery)
Expand Down
6 changes: 6 additions & 0 deletions datanode/sqlstore/liquidity_provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,9 @@ func addLiquidityProvisionsMultiProvider(ctx context.Context, t *testing.T, bs *
LastEpochFeePenalty: "0",
LastEpochBondPenalty: "0",
HysteresisPeriodFeePenalties: []string{"0"},
RequiredLiquidity: "1000",
NotionalVolumeBuys: "1010",
NotionalVolumeSells: "1005",
})
md.SyntheticTime = vegaTime
md.VegaTime = vegaTime
Expand Down Expand Up @@ -1024,6 +1027,9 @@ func addLiquidityProvisionsMultiProvider(ctx context.Context, t *testing.T, bs *
LastEpochFeePenalty: "0",
LastEpochBondPenalty: "0",
HysteresisPeriodFeePenalties: []string{"0"},
RequiredLiquidity: "1000",
NotionalVolumeBuys: "1010",
NotionalVolumeSells: "1005",
},
})
}
Expand Down
3 changes: 3 additions & 0 deletions protos/sources/vega/snapshot/v1/snapshot.proto
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,9 @@ message LiquidityV2PerformancePerParty {
string last_epoch_fraction_of_time_on_book = 6;
string last_epoch_fee_penalty = 7;
string last_epoch_bond_penalty = 8;
string required_liquidity = 9;
string notional_volume_buys = 10;
string notional_volume_sells = 11;
}

message LiquidityV2Scores {
Expand Down
Loading

0 comments on commit 2b4cf98

Please sign in to comment.