Skip to content

Commit

Permalink
feat: disable bon penalty for 7 epoch
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Letang <me@jeremyletang.com>
  • Loading branch information
jeremyletang committed Nov 1, 2023
1 parent 3f34414 commit 8866cf2
Show file tree
Hide file tree
Showing 5 changed files with 586 additions and 546 deletions.
4 changes: 4 additions & 0 deletions core/liquidity/v2/engine.go
Expand Up @@ -153,6 +153,10 @@ type Engine struct {
// 72 > 73, as we would need to cancel all remaining LP
// order which are eventually still seating in the book.
legacyOrderIDs []string

// Disable the penalties for a few epochs so the participants
// can adapt their strategies, to be removed in future releases
bondPenaltiesDisabledRemainingEpochs uint64
}

// NewEngine returns a new Liquidity Engine.
Expand Down
15 changes: 14 additions & 1 deletion core/liquidity/v2/sla.go
Expand Up @@ -38,6 +38,12 @@ func (e *Engine) ResetSLAEpoch(
midPrice *num.Uint,
positionFactor num.Decimal,
) {
// to be removed later, decrease the counter of epoch with
// penalties disabled
if e.bondPenaltiesDisabledRemainingEpochs != 0 {
e.bondPenaltiesDisabledRemainingEpochs -= 1
}

e.allocatedFeesStats = types.NewLiquidityFeeStats()
e.slaEpochStart = now

Expand Down Expand Up @@ -223,9 +229,16 @@ func (e *Engine) calculateCurrentFeePenalty(timeBookFraction num.Decimal) num.De
}

func (e *Engine) calculateBondPenalty(timeBookFraction num.Decimal) num.Decimal {
bondPenaltyMax := e.nonPerformanceBondPenaltyMax

// if bond penalty are still disable, set it to zero
if e.bondPenaltiesDisabledRemainingEpochs > 0 {
bondPenaltyMax = num.DecimalZero()
}

// min(nonPerformanceBondPenaltyMax, nonPerformanceBondPenaltySlope * (1-timeBookFraction/commitmentMinTimeFraction))
min := num.MinD(
e.nonPerformanceBondPenaltyMax,
bondPenaltyMax,
e.nonPerformanceBondPenaltySlope.Mul(num.DecimalOne().Sub(timeBookFraction.Div(e.slaParams.CommitmentMinTimeFraction))),
)

Expand Down
23 changes: 16 additions & 7 deletions core/liquidity/v2/snapshot.go
Expand Up @@ -23,6 +23,7 @@ import (

"code.vegaprotocol.io/vega/core/events"
"code.vegaprotocol.io/vega/core/types"
vgcontext "code.vegaprotocol.io/vega/libs/context"
"code.vegaprotocol.io/vega/libs/num"
"code.vegaprotocol.io/vega/libs/proto"
"code.vegaprotocol.io/vega/logging"
Expand Down Expand Up @@ -113,7 +114,7 @@ func (e *snapshotV2) LoadState(ctx context.Context, p *types.Payload) ([]types.S
case *types.PayloadLiquidityV2Scores:
return nil, e.loadScores(pl.Scores, p)
case *types.PayloadLiquidityV2Parameters:
return nil, e.loadParameters(pl.Parameters, p)
return nil, e.loadParameters(ctx, pl.Parameters, p)
case *types.PayloadPaidLiquidityV2FeeStats:
e.loadFeeStats(pl.Stats, p)
return nil, nil
Expand Down Expand Up @@ -346,11 +347,12 @@ func (e *snapshotV2) serialiseParameters() ([]byte, error) {
payload := &snapshotpb.Payload{
Data: &snapshotpb.Payload_LiquidityV2Parameters{
LiquidityV2Parameters: &snapshotpb.LiquidityV2Parameters{
MarketId: e.market,
MarketSlaParameters: e.slaParams.IntoProto(),
StakeToVolume: e.stakeToCcyVolume.String(),
BondPenaltySlope: e.nonPerformanceBondPenaltySlope.String(),
BondPenaltyMax: e.nonPerformanceBondPenaltyMax.String(),
MarketId: e.market,
MarketSlaParameters: e.slaParams.IntoProto(),
StakeToVolume: e.stakeToCcyVolume.String(),
BondPenaltySlope: e.nonPerformanceBondPenaltySlope.String(),
BondPenaltyMax: e.nonPerformanceBondPenaltyMax.String(),
BondPenaltiesDisabledRemainingEpochs: e.bondPenaltiesDisabledRemainingEpochs,
},
},
}
Expand Down Expand Up @@ -505,9 +507,16 @@ func (e *snapshotV2) loadScores(ls *snapshotpb.LiquidityV2Scores, p *types.Paylo
return err
}

func (e *snapshotV2) loadParameters(ls *snapshotpb.LiquidityV2Parameters, p *types.Payload) error {
func (e *snapshotV2) loadParameters(ctx context.Context, ls *snapshotpb.LiquidityV2Parameters, p *types.Payload) error {
var err error

if vgcontext.InProgressUpgradeFrom(ctx, "v0.73.1") {
// on the upgrade we set this value to be 7 epochs
e.bondPenaltiesDisabledRemainingEpochs = 7
} else {
e.bondPenaltiesDisabledRemainingEpochs = ls.BondPenaltiesDisabledRemainingEpochs
}

// market SLA parameters
e.slaParams = types.LiquiditySLAParamsFromProto(ls.MarketSlaParameters)

Expand Down
1 change: 1 addition & 0 deletions protos/sources/vega/snapshot/v1/snapshot.proto
Expand Up @@ -925,6 +925,7 @@ message LiquidityV2Parameters {
string stake_to_volume = 3;
string bond_penalty_slope = 4;
string bond_penalty_max = 5;
uint64 bond_penalties_disabled_remaining_epochs = 6;
}

message LiquidityV2PaidFeesStats {
Expand Down

0 comments on commit 8866cf2

Please sign in to comment.