From 5f466e8a3e8eaba1a4767e117abb48201b4a12e0 Mon Sep 17 00:00:00 2001 From: Elias Van Ootegem Date: Tue, 7 Nov 2023 09:57:35 +0000 Subject: [PATCH] feat: add liquidation strategy validation to governance engine Signed-off-by: Elias Van Ootegem --- core/governance/market.go | 24 ++++++++++++++++++++++++ core/types/governance_new_market.go | 3 +++ core/types/governance_update_market.go | 3 +++ 3 files changed, 30 insertions(+) diff --git a/core/governance/market.go b/core/governance/market.go index 701c337164e..d62131a7d3a 100644 --- a/core/governance/market.go +++ b/core/governance/market.go @@ -649,6 +649,24 @@ func validateRiskParameters(rp interface{}) (types.ProposalError, error) { } } +func validateLiquidationStrategy(ls *types.LiquidationStrategy) (types.ProposalError, error) { + if ls == nil { + // @TODO this will become a required parameter, but for now leave it as is + // this will be implemented in at a later stage + return types.ProposalErrorUnspecified, nil + } + if ls.DisposalFraction.IsZero() || ls.DisposalFraction.IsNegative() || ls.DisposalFraction.GreaterThan(num.DecimalOne()) { + return types.ProposalErrorInvalidMarket, fmt.Errorf("liquidation strategy disposal fraction must be in the 0-1 range and non-zero") + } + if ls.MaxFractionConsumed.IsZero() || ls.DisposalFraction.IsNegative() || ls.DisposalFraction.GreaterThan(num.DecimalOne()) { + return types.ProposalErrorInvalidMarket, fmt.Errorf("liquidation max fraction must be in the 0-1 range and non-zero") + } + if ls.DisposalTimeStep < 0 { + return types.ProposalErrorInvalidMarket, fmt.Errorf("liquidation time can't be negative") + } + return types.ProposalErrorUnspecified, nil +} + func validateLPSLAParams(slaParams *types.LiquiditySLAParams) (types.ProposalError, error) { if slaParams == nil { return types.ProposalErrorMissingSLAParams, fmt.Errorf("liquidity provision SLA must be provided") @@ -766,6 +784,9 @@ func validateNewMarketChange( if perr, err := validateSlippageFactor(terms.Changes.QuadraticSlippageFactor, false); err != nil { return perr, err } + if perr, err := validateLiquidationStrategy(terms.Changes.LiquidationStrategy); err != nil { + return perr, err + } return types.ProposalErrorUnspecified, nil } @@ -836,6 +857,9 @@ func validateUpdateMarketChange(terms *types.UpdateMarket, mkt types.Market, etu if perr, err := validateSlippageFactor(terms.Changes.QuadraticSlippageFactor, false); err != nil { return perr, err } + if perr, err := validateLiquidationStrategy(terms.Changes.LiquidationStrategy); err != nil { + return perr, err + } return types.ProposalErrorUnspecified, nil } diff --git a/core/types/governance_new_market.go b/core/types/governance_new_market.go index efd92d84b12..0886c05de0c 100644 --- a/core/types/governance_new_market.go +++ b/core/types/governance_new_market.go @@ -258,6 +258,9 @@ func (n NewMarketConfiguration) DeepClone() *NewMarketConfiguration { cs := *n.Successor cpy.Successor = &cs } + if n.LiquidationStrategy != nil { + cpy.LiquidationStrategy = n.LiquidationStrategy.DeepClone() + } return cpy } diff --git a/core/types/governance_update_market.go b/core/types/governance_update_market.go index 3cc799e2e17..e125759f922 100644 --- a/core/types/governance_update_market.go +++ b/core/types/governance_update_market.go @@ -173,6 +173,9 @@ func (n UpdateMarketConfiguration) DeepClone() *UpdateMarketConfiguration { if n.LiquidityFeeSettings != nil { cpy.LiquidityFeeSettings = n.LiquidityFeeSettings.DeepClone() } + if n.LiquidationStrategy != nil { + cpy.LiquidationStrategy = n.LiquidationStrategy.DeepClone() + } return cpy }