Skip to content

Commit

Permalink
feat: add liquidation strategy validation to governance engine
Browse files Browse the repository at this point in the history
Signed-off-by: Elias Van Ootegem <[email protected]>
  • Loading branch information
EVODelavega committed Nov 7, 2023
1 parent ca056b3 commit 5f466e8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions core/governance/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions core/types/governance_new_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions core/types/governance_update_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 5f466e8

Please sign in to comment.