Skip to content

Commit

Permalink
Merge pull request #10348 from vegaprotocol/mark_price
Browse files Browse the repository at this point in the history
feat: add oracle support to the new mark price
  • Loading branch information
ze97286 authored Jan 10, 2024
2 parents 81f4bca + a011c3e commit 0430813
Show file tree
Hide file tree
Showing 32 changed files with 2,090 additions and 669 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
- [462](https://github.com/vegaprotocol/core-test-coverage/issues/462) - Cover `0012-POSR-011` explicitly
- [595](https://github.com/vegaprotocol/core-test-coverage/issues/595) - Ensure the full size of iceberg orders is considered when creating a network order.
- [10308](https://github.com/vegaprotocol/vega/issues/10308) - Support joining to closed teams based on an allow list.
- [10349](https://github.com/vegaprotocol/vega/issues/10349) - Add oracle support to mark price configuration.
- [10350](https://github.com/vegaprotocol/vega/issues/10350) - Set mark price to uncrossing price if at the end of opening auction no price was yielded by the mark price methodology.
- [521](https://github.com/vegaprotocol/core-test-coverage/issues/521) - Add tests for allow list functionality when joining teams.

### 🐛 Fixes
Expand Down
101 changes: 80 additions & 21 deletions commands/proposal_submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,22 @@ func isBindingMatchingSpecFilters(spec *vegapb.DataSourceDefinition, bindingProp
return bindingPropertyFound
}

func checkCompositePriceBinding(binding *vegapb.SpecBindingForCompositePrice, definition *vegapb.DataSourceDefinition, property string) Errors {
errs := NewErrors()

if binding == nil {
errs.AddForProperty(property, ErrIsRequired)
return errs
}

if len(binding.PriceSourceProperty) == 0 {
errs.AddForProperty(property, ErrIsRequired)
} else if !isBindingMatchingSpec(definition, binding.PriceSourceProperty) {
errs.AddForProperty(fmt.Sprintf("%s.price_source_property", property), ErrIsMismatching)
}
return errs
}

func checkNewOracleBinding(future *protoTypes.FutureProduct) Errors {
errs := NewErrors()
if future.DataSourceSpecBinding != nil {
Expand Down Expand Up @@ -1873,38 +1889,62 @@ func checkLiquidityFeeSettings(config *protoTypes.LiquidityFeeSettings, parent s
func checkCompositePriceConfiguration(config *protoTypes.CompositePriceConfiguration, parent string) Errors {
errs := NewErrors()
if config == nil {
errs.AddForProperty(parent, ErrIsNotValid)
errs.AddForProperty(parent, ErrIsRequired)
return errs
}
if config.DecayPower > 3 {
errs.AddForProperty(fmt.Sprintf("%s.decay_power", parent), fmt.Errorf("must be in {0, 1, 2, 3}"))
if config.CompositePriceType == protoTypes.CompositePriceType_COMPOSITE_PRICE_TYPE_UNSPECIFIED {
errs.AddForProperty(fmt.Sprintf("%s.composite_price_type", parent), ErrIsRequired)
}
if len(config.DecayWeight) == 0 {
errs.AddForProperty(fmt.Sprintf("%s.decay_weight", parent), ErrIsRequired)
} else {
dw, err := num.DecimalFromString(config.DecayWeight)
if err != nil {
errs.AddForProperty(fmt.Sprintf("%s.decay_weight", parent), ErrIsNotValidNumber)

if _, ok := protoTypes.CompositePriceType_name[int32(config.CompositePriceType)]; !ok {
errs.AddForProperty(fmt.Sprintf("%s.composite_price_type", parent), ErrIsNotValid)
}

if config.CompositePriceType != protoTypes.CompositePriceType_COMPOSITE_PRICE_TYPE_LAST_TRADE {
if config.DecayPower > 3 || config.DecayPower < 1 {
errs.AddForProperty(fmt.Sprintf("%s.decay_power", parent), fmt.Errorf("must be in {1, 2, 3}"))
}
if len(config.DecayWeight) == 0 {
errs.AddForProperty(fmt.Sprintf("%s.decay_weight", parent), ErrIsRequired)
} else {
if dw.LessThan(num.DecimalZero()) || dw.GreaterThan(num.DecimalOne()) {
dw, err := num.DecimalFromString(config.DecayWeight)
if err != nil {
errs.AddForProperty(fmt.Sprintf("%s.decay_weight", parent), ErrIsNotValidNumber)
} else if dw.LessThan(num.DecimalZero()) || dw.GreaterThan(num.DecimalOne()) {
errs.AddForProperty(fmt.Sprintf("%s.decay_weight", parent), ErrMustBeWithinRange01)
}
}
}
if len(config.CashAmount) == 0 {
errs.AddForProperty(fmt.Sprintf("%s.cash_amount", parent), ErrIsRequired)
} else {
if n, overflow := num.UintFromString(config.CashAmount, 10); overflow || n.IsNegative() {
if len(config.CashAmount) == 0 {
errs.AddForProperty(fmt.Sprintf("%s.cash_amount", parent), ErrIsRequired)
} else if n, overflow := num.UintFromString(config.CashAmount, 10); overflow || n.IsNegative() {
errs.AddForProperty(fmt.Sprintf("%s.cash_amount", parent), ErrIsNotValidNumber)
}
} else {
if config.DecayPower != 0 {
errs.AddForProperty(fmt.Sprintf("%s.decay_power", parent), fmt.Errorf("must not be defined for price type last trade"))
}
if len(config.DecayWeight) > 0 {
errs.AddForProperty(fmt.Sprintf("%s.decay_weight", parent), fmt.Errorf("must not be defined for price type last trade"))
}
if len(config.CashAmount) > 0 {
errs.AddForProperty(fmt.Sprintf("%s.cash_amount", parent), fmt.Errorf("must not be defined for price type last trade"))
}
if len(config.SourceStalenessTolerance) > 0 {
errs.AddForProperty(fmt.Sprintf("%s.source_staleness_tolerance", parent), fmt.Errorf("must not be defined for price type last trade"))
}
if len(config.SourceWeights) > 0 {
errs.AddForProperty(fmt.Sprintf("%s.source_weights", parent), fmt.Errorf("must not be defined for price type last trade"))
}
if len(config.DataSourcesSpec) > 0 {
errs.AddForProperty(fmt.Sprintf("%s.data_sources_spec", parent), fmt.Errorf("must not be defined for price type last trade"))
}
if len(config.DataSourcesSpec) > 0 {
errs.AddForProperty(fmt.Sprintf("%s.data_sources_spec_binding", parent), fmt.Errorf("must not be defined for price type last trade"))
}
}

if config.CompositePriceType == protoTypes.CompositePriceType_COMPOSITE_PRICE_TYPE_UNSPECIFIED {
errs.AddForProperty(fmt.Sprintf("%s.composite_price_type", parent), ErrIsRequired)
}

if _, ok := protoTypes.CompositePriceType_name[int32(config.CompositePriceType)]; !ok {
errs.AddForProperty(fmt.Sprintf("%s.composite_price_type", parent), ErrIsNotValid)
if config.CompositePriceType != protoTypes.CompositePriceType_COMPOSITE_PRICE_TYPE_WEIGHTED && len(config.SourceWeights) > 0 {
errs.AddForProperty(fmt.Sprintf("%s.source_weights", parent), fmt.Errorf("must be empty if composite price type is not weighted"))
}

if config.CompositePriceType == protoTypes.CompositePriceType_COMPOSITE_PRICE_TYPE_WEIGHTED && len(config.SourceWeights) < 4 {
Expand Down Expand Up @@ -1932,6 +1972,25 @@ func checkCompositePriceConfiguration(config *protoTypes.CompositePriceConfigura
errs.AddForProperty(fmt.Sprintf("%s.source_staleness_tolerance.%d", parent, i), fmt.Errorf("must be a valid duration"))
}
}
if len(config.DataSourcesSpec) > 0 && len(config.DataSourcesSpec) != len(config.DataSourcesSpecBinding) {
errs.AddForProperty(fmt.Sprintf("%s.data_sources_spec", parent), fmt.Errorf("must be have the same number of elements as the corresponding bindings"))
}
if len(config.DataSourcesSpec) > 5 {
errs.AddForProperty(fmt.Sprintf("%s.data_sources_spec", parent), fmt.Errorf("too many data source specs - must be less than or equal to 5"))
}
if len(config.DataSourcesSpec) > 0 && len(config.SourceStalenessTolerance) != 3+len(config.DataSourcesSpec) {
errs.AddForProperty(fmt.Sprintf("%s.source_staleness_tolerance", parent), fmt.Errorf("must included staleness information for all data sources"))
}

if config.CompositePriceType == protoTypes.CompositePriceType_COMPOSITE_PRICE_TYPE_LAST_TRADE && len(config.DataSourcesSpec) > 0 {
errs.AddForProperty(fmt.Sprintf("%s.data_sources_spec", parent), fmt.Errorf("are not supported for last trade composite price type"))
}
if len(config.DataSourcesSpec) > 0 {
for i, dsd := range config.DataSourcesSpec {
errs.Merge(checkDataSourceSpec(dsd, fmt.Sprintf("data_sources_spec.%d", i), parent, true))
errs.Merge(checkCompositePriceBinding(config.DataSourcesSpecBinding[i], dsd, fmt.Sprintf("%s.data_sources_spec_binding.%d", parent, i)))
}
}

return errs
}
Expand Down
Loading

0 comments on commit 0430813

Please sign in to comment.