-
Notifications
You must be signed in to change notification settings - Fork 19
/
market.go
1050 lines (933 loc) · 42.9 KB
/
market.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2023 Gobalsky Labs Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package governance
import (
"errors"
"fmt"
"strconv"
"time"
dsdefinition "code.vegaprotocol.io/vega/core/datasource/definition"
ethcallcommon "code.vegaprotocol.io/vega/core/datasource/external/ethcall/common"
"code.vegaprotocol.io/vega/core/datasource"
"code.vegaprotocol.io/vega/core/datasource/spec"
"code.vegaprotocol.io/vega/core/netparams"
"code.vegaprotocol.io/vega/core/types"
"code.vegaprotocol.io/vega/libs/num"
"code.vegaprotocol.io/vega/libs/ptr"
proto "code.vegaprotocol.io/vega/protos/vega"
datapb "code.vegaprotocol.io/vega/protos/vega/data/v1"
)
var (
// ErrMissingProduct is returned if selected product is nil.
ErrMissingProduct = errors.New("missing product")
// ErrUnsupportedProduct is returned if selected product is not supported.
ErrUnsupportedProduct = errors.New("product type is not supported")
// ErrUnsupportedRiskParameters is returned if risk parameters supplied via governance are not yet supported.
ErrUnsupportedRiskParameters = errors.New("risk model parameters are not supported")
// ErrMissingRiskParameters ...
ErrMissingRiskParameters = errors.New("missing risk parameters")
// ErrMissingDataSourceSpecBinding is returned when the data source spec binding is absent.
ErrMissingDataSourceSpecBinding = errors.New("missing data source spec binding")
// ErrMissingDataSourceSpecForSettlementData is returned when the data source spec for settlement data is absent.
ErrMissingDataSourceSpecForSettlementData = errors.New("missing data source spec for settlement data")
// ErrMissingDataSourceSpecForSettlementData is returned when the data source spec for settlement data is absent.
ErrSettlementWithInternalDataSourceIsNotAllowed = errors.New("settlement with internal data source is not allwed")
// ErrMissingDataSourceSpecForTradingTermination is returned when the data source spec for trading termination is absent.
ErrMissingDataSourceSpecForTradingTermination = errors.New("missing data source spec for trading termination")
// ErrMissingDataSourceSpecForSettlementSchedule is returned when the data source spec for trading termination is absent.
ErrMissingDataSourceSpecForSettlementSchedule = errors.New("missing data source spec for settlement schedule")
// ErrInternalTimeTriggerForFuturesInNotAllowed is returned when a proposal containing timetrigger terminaiton type of data is received.
ErrInternalTimeTriggerForFuturesInNotAllowed = errors.New("setting internal time trigger for future termination is not allowed")
// ErrDataSourceSpecTerminationTimeBeforeEnactment is returned when termination time is before enactment
// for time triggered termination condition.
ErrDataSourceSpecTerminationTimeBeforeEnactment = errors.New("data source spec termination time before enactment")
// ErrMissingPerpsProduct is returned when perps product is absent from the instrument.
ErrMissingPerpsProduct = errors.New("missing perps product")
// ErrMissingFutureProduct is returned when future product is absent from the instrument.
ErrMissingFutureProduct = errors.New("missing future product")
// ErrMissingSpotProduct is returned when spot product is absent from the instrument.
ErrMissingSpotProduct = errors.New("missing spot product")
// ErrInvalidRiskParameter ...
ErrInvalidRiskParameter = errors.New("invalid risk parameter")
// ErrInvalidInsurancePoolFraction is returned if the insurance pool fraction parameter is outside of the 0-1 range.
ErrInvalidInsurancePoolFraction = errors.New("insurnace pool fraction invalid")
ErrUpdateMarketDifferentProduct = errors.New("cannot update a market to a different product type")
)
func assignProduct(
source *types.InstrumentConfiguration,
target *types.Instrument,
) (proto.ProposalError, error) {
switch product := source.Product.(type) {
case *types.InstrumentConfigurationFuture:
if product.Future == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingFutureProduct
}
settlData := &product.Future.DataSourceSpecForSettlementData
if settlData == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecForSettlementData
}
tterm := &product.Future.DataSourceSpecForTradingTermination
if tterm == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecForTradingTermination
}
if product.Future.DataSourceSpecBinding == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecBinding
}
target.Product = &types.InstrumentFuture{
Future: &types.Future{
SettlementAsset: product.Future.SettlementAsset,
QuoteName: product.Future.QuoteName,
DataSourceSpecForSettlementData: datasource.SpecFromDefinition(product.Future.DataSourceSpecForSettlementData),
DataSourceSpecForTradingTermination: datasource.SpecFromDefinition(product.Future.DataSourceSpecForTradingTermination),
DataSourceSpecBinding: product.Future.DataSourceSpecBinding,
},
}
case *types.InstrumentConfigurationPerps:
if product.Perps == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingPerpsProduct
}
settlData := &product.Perps.DataSourceSpecForSettlementData
if settlData == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecForSettlementData
}
settlSchedule := &product.Perps.DataSourceSpecForSettlementSchedule
if settlSchedule == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecForTradingTermination
}
if product.Perps.DataSourceSpecBinding == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecBinding
}
target.Product = &types.InstrumentPerps{
Perps: &types.Perps{
SettlementAsset: product.Perps.SettlementAsset,
QuoteName: product.Perps.QuoteName,
InterestRate: product.Perps.InterestRate,
MarginFundingFactor: product.Perps.MarginFundingFactor,
ClampLowerBound: product.Perps.ClampLowerBound,
ClampUpperBound: product.Perps.ClampUpperBound,
DataSourceSpecForSettlementData: datasource.SpecFromDefinition(product.Perps.DataSourceSpecForSettlementData),
DataSourceSpecForSettlementSchedule: datasource.SpecFromDefinition(product.Perps.DataSourceSpecForSettlementSchedule),
DataSourceSpecBinding: product.Perps.DataSourceSpecBinding,
},
}
case *types.InstrumentConfigurationSpot:
if product.Spot == nil {
return types.ProposalErrorInvalidSpot, ErrMissingSpotProduct
}
target.Product = &types.InstrumentSpot{
Spot: &types.Spot{
Name: product.Spot.Name,
BaseAsset: product.Spot.BaseAsset,
QuoteAsset: product.Spot.QuoteAsset,
},
}
default:
return types.ProposalErrorUnsupportedProduct, ErrUnsupportedProduct
}
return types.ProposalErrorUnspecified, nil
}
func createInstrument(
input *types.InstrumentConfiguration,
tags []string,
) (*types.Instrument, types.ProposalError, error) {
result := &types.Instrument{
Name: input.Name,
Code: input.Code,
Metadata: &types.InstrumentMetadata{
Tags: tags,
},
}
if perr, err := assignProduct(input, result); err != nil {
return nil, perr, err
}
return result, types.ProposalErrorUnspecified, nil
}
func assignRiskModel(definition *types.NewMarketConfiguration, target *types.TradableInstrument) error {
switch parameters := definition.RiskParameters.(type) {
case *types.NewMarketConfigurationSimple:
target.RiskModel = &types.TradableInstrumentSimpleRiskModel{
SimpleRiskModel: &types.SimpleRiskModel{
Params: parameters.Simple,
},
}
case *types.NewMarketConfigurationLogNormal:
target.RiskModel = &types.TradableInstrumentLogNormalRiskModel{
LogNormalRiskModel: parameters.LogNormal,
}
default:
return ErrUnsupportedRiskParameters
}
return nil
}
func assignSpotRiskModel(definition *types.NewSpotMarketConfiguration, target *types.TradableInstrument) error {
switch parameters := definition.RiskParameters.(type) {
case *types.NewSpotMarketConfigurationSimple:
target.RiskModel = &types.TradableInstrumentSimpleRiskModel{
SimpleRiskModel: &types.SimpleRiskModel{
Params: parameters.Simple,
},
}
case *types.NewSpotMarketConfigurationLogNormal:
target.RiskModel = &types.TradableInstrumentLogNormalRiskModel{
LogNormalRiskModel: parameters.LogNormal,
}
default:
return ErrUnsupportedRiskParameters
}
return nil
}
func buildMarketFromProposal(
marketID string,
definition *types.NewMarket,
netp NetParams,
openingAuctionDuration time.Duration,
) (*types.Market, types.ProposalError, error) {
instrument, perr, err := createInstrument(definition.Changes.Instrument, definition.Changes.Metadata)
if err != nil {
return nil, perr, err
}
// get factors for the market
makerFee, _ := netp.Get(netparams.MarketFeeFactorsMakerFee)
infraFee, _ := netp.Get(netparams.MarketFeeFactorsInfrastructureFee)
// get the margin scaling factors
scalingFactors := proto.ScalingFactors{}
_ = netp.GetJSONStruct(netparams.MarketMarginScalingFactors, &scalingFactors)
// get price monitoring parameters
if definition.Changes.PriceMonitoringParameters == nil {
pmParams := &proto.PriceMonitoringParameters{}
_ = netp.GetJSONStruct(netparams.MarketPriceMonitoringDefaultParameters, pmParams)
definition.Changes.PriceMonitoringParameters = types.PriceMonitoringParametersFromProto(pmParams)
}
makerFeeDec, _ := num.DecimalFromString(makerFee)
infraFeeDec, _ := num.DecimalFromString(infraFee)
market := &types.Market{
ID: marketID,
DecimalPlaces: definition.Changes.DecimalPlaces,
PositionDecimalPlaces: definition.Changes.PositionDecimalPlaces,
Fees: &types.Fees{
Factors: &types.FeeFactors{
MakerFee: makerFeeDec,
InfrastructureFee: infraFeeDec,
},
},
OpeningAuction: &types.AuctionDuration{
Duration: int64(openingAuctionDuration.Seconds()),
},
TradableInstrument: &types.TradableInstrument{
Instrument: instrument,
MarginCalculator: &types.MarginCalculator{
ScalingFactors: types.ScalingFactorsFromProto(&scalingFactors),
},
},
PriceMonitoringSettings: &types.PriceMonitoringSettings{
Parameters: definition.Changes.PriceMonitoringParameters,
},
LiquidityMonitoringParameters: definition.Changes.LiquidityMonitoringParameters,
LiquiditySLAParams: definition.Changes.LiquiditySLAParameters,
LinearSlippageFactor: definition.Changes.LinearSlippageFactor,
QuadraticSlippageFactor: definition.Changes.QuadraticSlippageFactor,
}
// successor proposal
if suc := definition.Successor(); suc != nil {
market.ParentMarketID = suc.ParentID
market.InsurancePoolFraction = suc.InsurancePoolFraction
}
if err := assignRiskModel(definition.Changes, market.TradableInstrument); err != nil {
return nil, types.ProposalErrorUnspecified, err
}
return market, types.ProposalErrorUnspecified, nil
}
func buildSpotMarketFromProposal(
marketID string,
definition *types.NewSpotMarket,
netp NetParams,
openingAuctionDuration time.Duration,
) (*types.Market, types.ProposalError, error) {
instrument, perr, err := createInstrument(definition.Changes.Instrument, definition.Changes.Metadata)
if err != nil {
return nil, perr, err
}
// get factors for the market
makerFee, _ := netp.Get(netparams.MarketFeeFactorsMakerFee)
infraFee, _ := netp.Get(netparams.MarketFeeFactorsInfrastructureFee)
// get price monitoring parameters
if definition.Changes.PriceMonitoringParameters == nil {
pmParams := &proto.PriceMonitoringParameters{}
_ = netp.GetJSONStruct(netparams.MarketPriceMonitoringDefaultParameters, pmParams)
definition.Changes.PriceMonitoringParameters = types.PriceMonitoringParametersFromProto(pmParams)
}
liquidityMonitoring := &types.LiquidityMonitoringParameters{
TargetStakeParameters: definition.Changes.TargetStakeParameters,
TriggeringRatio: num.DecimalZero(),
AuctionExtension: 0,
}
makerFeeDec, _ := num.DecimalFromString(makerFee)
infraFeeDec, _ := num.DecimalFromString(infraFee)
market := &types.Market{
ID: marketID,
DecimalPlaces: definition.Changes.DecimalPlaces,
PositionDecimalPlaces: definition.Changes.PositionDecimalPlaces,
Fees: &types.Fees{
Factors: &types.FeeFactors{
MakerFee: makerFeeDec,
InfrastructureFee: infraFeeDec,
},
},
OpeningAuction: &types.AuctionDuration{
Duration: int64(openingAuctionDuration.Seconds()),
},
TradableInstrument: &types.TradableInstrument{
Instrument: instrument,
MarginCalculator: &types.MarginCalculator{
ScalingFactors: &types.ScalingFactors{
SearchLevel: num.DecimalZero(),
InitialMargin: num.DecimalZero(),
CollateralRelease: num.DecimalZero(),
},
},
},
PriceMonitoringSettings: &types.PriceMonitoringSettings{
Parameters: definition.Changes.PriceMonitoringParameters,
},
LiquidityMonitoringParameters: liquidityMonitoring,
LinearSlippageFactor: num.DecimalZero(),
QuadraticSlippageFactor: num.DecimalZero(),
LiquiditySLAParams: definition.Changes.SLAParams,
}
if err := assignSpotRiskModel(definition.Changes, market.TradableInstrument); err != nil {
return nil, types.ProposalErrorUnspecified, err
}
return market, types.ProposalErrorUnspecified, nil
}
func validateAssetBasic(assetID string, assets Assets, deepCheck bool) (types.ProposalError, error) {
if len(assetID) <= 0 {
return types.ProposalErrorInvalidAsset, errors.New("missing asset ID")
}
if !deepCheck {
return types.ProposalErrorUnspecified, nil
}
_, err := assets.Get(assetID)
if err != nil {
return types.ProposalErrorInvalidAsset, err
}
if !assets.IsEnabled(assetID) {
return types.ProposalErrorInvalidAsset,
fmt.Errorf("asset is not enabled %v", assetID)
}
return types.ProposalErrorUnspecified, nil
}
func validateAsset(assetID string, decimals uint64, assets Assets, deepCheck bool) (types.ProposalError, error) {
if len(assetID) <= 0 {
return types.ProposalErrorInvalidAsset, errors.New("missing asset ID")
}
if !deepCheck {
return types.ProposalErrorUnspecified, nil
}
asset, err := assets.Get(assetID)
if err != nil {
return types.ProposalErrorInvalidAsset, err
}
if !assets.IsEnabled(assetID) {
return types.ProposalErrorInvalidAsset,
fmt.Errorf("assets is not enabled %v", assetID)
}
// decimal places asset less than market -> invalid.
// @TODO add a specific error for this validation?
if asset.DecimalPlaces() < decimals {
return types.ProposalErrorTooManyMarketDecimalPlaces, errors.New("market cannot have more decimal places than assets")
}
return types.ProposalErrorUnspecified, nil
}
func validateSpot(spot *types.SpotProduct, decimals uint64, assets Assets, deepCheck bool) (types.ProposalError, error) {
propError, err := validateAsset(spot.QuoteAsset, decimals, assets, deepCheck)
if err != nil {
return propError, err
}
return validateAssetBasic(spot.BaseAsset, assets, deepCheck)
}
func validateFuture(future *types.FutureProduct, decimals uint64, assets Assets, et *enactmentTime, deepCheck bool) (types.ProposalError, error) {
future.DataSourceSpecForSettlementData = setDatasourceDefinitionDefaults(future.DataSourceSpecForSettlementData, et)
future.DataSourceSpecForTradingTermination = setDatasourceDefinitionDefaults(future.DataSourceSpecForTradingTermination, et)
settlData := &future.DataSourceSpecForSettlementData
if settlData == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecForSettlementData
}
if settlData.Content() == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecForSettlementData
}
ext, err := settlData.IsExternal()
if err != nil {
return types.ProposalErrorInvalidFutureProduct, err
}
if !ext {
return types.ProposalErrorInvalidFutureProduct, ErrSettlementWithInternalDataSourceIsNotAllowed
}
tterm := &future.DataSourceSpecForTradingTermination
if tterm == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecForTradingTermination
}
if tterm.Content() == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecForTradingTermination
}
tp, _ := tterm.Type()
if tp == datasource.ContentTypeInternalTimeTriggerTermination {
return types.ProposalErrorInvalidFutureProduct, ErrInternalTimeTriggerForFuturesInNotAllowed
}
filters := future.DataSourceSpecForTradingTermination.GetFilters()
for i, f := range filters {
if f.Key.Type == datapb.PropertyKey_TYPE_TIMESTAMP {
for j, cond := range f.Conditions {
v, err := strconv.ParseInt(cond.Value, 10, 64)
if err != nil {
return types.ProposalErrorInvalidFutureProduct, err
}
filters[i].Conditions[j].Value = strconv.FormatInt(v, 10)
if !et.shouldNotVerify {
if v <= et.current {
return types.ProposalErrorInvalidFutureProduct, ErrDataSourceSpecTerminationTimeBeforeEnactment
}
}
}
}
}
future.DataSourceSpecForTradingTermination.UpdateFilters(filters)
if future.DataSourceSpecBinding == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecBinding
}
// ensure the oracle spec for settlement data can be constructed
ospec, err := spec.New(*datasource.SpecFromDefinition(future.DataSourceSpecForSettlementData))
if err != nil {
return types.ProposalErrorInvalidFutureProduct, err
}
switch future.DataSourceSpecBinding.SettlementDataProperty {
case datapb.PropertyKey_TYPE_DECIMAL.String():
err := ospec.EnsureBoundableProperty(future.DataSourceSpecBinding.SettlementDataProperty, datapb.PropertyKey_TYPE_DECIMAL)
if err != nil {
return types.ProposalErrorInvalidFutureProduct, fmt.Errorf("invalid oracle spec binding for settlement data: %w", err)
}
default:
err := ospec.EnsureBoundableProperty(future.DataSourceSpecBinding.SettlementDataProperty, datapb.PropertyKey_TYPE_INTEGER)
if err != nil {
return types.ProposalErrorInvalidFutureProduct, fmt.Errorf("invalid oracle spec binding for settlement data: %w", err)
}
}
// ensure the oracle spec for market termination can be constructed
ospec, err = spec.New(*datasource.SpecFromDefinition(future.DataSourceSpecForTradingTermination))
if err != nil {
return types.ProposalErrorInvalidFutureProduct, err
}
switch future.DataSourceSpecBinding.TradingTerminationProperty {
case spec.BuiltinTimestamp:
if err := ospec.EnsureBoundableProperty(future.DataSourceSpecBinding.TradingTerminationProperty, datapb.PropertyKey_TYPE_TIMESTAMP); err != nil {
return types.ProposalErrorInvalidFutureProduct, fmt.Errorf("invalid oracle spec binding for trading termination: %w", err)
}
default:
if err := ospec.EnsureBoundableProperty(future.DataSourceSpecBinding.TradingTerminationProperty, datapb.PropertyKey_TYPE_BOOLEAN); err != nil {
return types.ProposalErrorInvalidFutureProduct, fmt.Errorf("invalid oracle spec binding for trading termination: %w", err)
}
}
return validateAsset(future.SettlementAsset, decimals, assets, deepCheck)
}
func validatePerps(perps *types.PerpsProduct, decimals uint64, assets Assets, et *enactmentTime, currentTime time.Time, deepCheck bool) (types.ProposalError, error) {
perps.DataSourceSpecForSettlementData = setDatasourceDefinitionDefaults(perps.DataSourceSpecForSettlementData, et)
perps.DataSourceSpecForSettlementSchedule = setDatasourceDefinitionDefaults(perps.DataSourceSpecForSettlementSchedule, et)
settlData := &perps.DataSourceSpecForSettlementData
if settlData == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecForSettlementData
}
if settlData.Content() == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecForSettlementData
}
ext, err := settlData.IsExternal()
if err != nil {
return types.ProposalErrorInvalidPerpsProduct, err
}
if !ext {
return types.ProposalErrorInvalidPerpsProduct, ErrSettlementWithInternalDataSourceIsNotAllowed
}
settlSchedule := &perps.DataSourceSpecForSettlementSchedule
if settlSchedule == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecForSettlementSchedule
}
if settlSchedule.Content() == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecForSettlementSchedule
}
if perps.DataSourceSpecBinding == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecBinding
}
// ensure the oracle spec for settlement data can be constructed
ospec, err := spec.New(*datasource.SpecFromDefinition(perps.DataSourceSpecForSettlementData))
if err != nil {
return types.ProposalErrorInvalidPerpsProduct, err
}
switch perps.DataSourceSpecBinding.SettlementDataProperty {
case datapb.PropertyKey_TYPE_DECIMAL.String():
err := ospec.EnsureBoundableProperty(perps.DataSourceSpecBinding.SettlementDataProperty, datapb.PropertyKey_TYPE_DECIMAL)
if err != nil {
return types.ProposalErrorInvalidPerpsProduct, fmt.Errorf("invalid oracle spec binding for settlement data: %w", err)
}
default:
err := ospec.EnsureBoundableProperty(perps.DataSourceSpecBinding.SettlementDataProperty, datapb.PropertyKey_TYPE_INTEGER)
if err != nil {
return types.ProposalErrorInvalidPerpsProduct, fmt.Errorf("invalid oracle spec binding for settlement data: %w", err)
}
}
// ensure the oracle spec for market termination can be constructed
ospec, err = spec.New(*datasource.SpecFromDefinition(perps.DataSourceSpecForSettlementSchedule))
if err != nil {
return types.ProposalErrorInvalidPerpsProduct, err
}
switch perps.DataSourceSpecBinding.SettlementScheduleProperty {
case spec.BuiltinTimeTrigger:
tt := perps.DataSourceSpecForSettlementSchedule.GetInternalTimeTriggerSpecConfiguration()
if len(tt.Triggers) != 1 {
return types.ProposalErrorInvalidPerpsProduct, fmt.Errorf("invalid settlement schedule, only 1 trigger allowed")
}
if tt.Triggers[0] == nil {
return types.ProposalErrorInvalidPerpsProduct, fmt.Errorf("at least 1 time trigger is required")
}
if tt.Triggers[0].Initial == nil {
tt.SetInitial(time.Unix(et.current, 0), currentTime)
}
tt.SetNextTrigger(currentTime)
// can't have the first trigger in the past
if tt.Triggers[0].Initial.Before(currentTime) {
return types.ProposalErrorInvalidPerpsProduct, fmt.Errorf("time trigger starts in the past")
}
if err := ospec.EnsureBoundableProperty(perps.DataSourceSpecBinding.SettlementScheduleProperty, datapb.PropertyKey_TYPE_TIMESTAMP); err != nil {
return types.ProposalErrorInvalidPerpsProduct, fmt.Errorf("invalid oracle spec binding for settlement schedule: %w", err)
}
default:
return types.ProposalErrorInvalidPerpsProduct, fmt.Errorf("time trigger only supported for now")
}
return validateAsset(perps.SettlementAsset, decimals, assets, deepCheck)
}
func validateNewInstrument(instrument *types.InstrumentConfiguration, decimals uint64, assets Assets, et *enactmentTime, deepCheck bool, currentTime *time.Time) (types.ProposalError, error) {
switch product := instrument.Product.(type) {
case nil:
return types.ProposalErrorNoProduct, ErrMissingProduct
case *types.InstrumentConfigurationFuture:
return validateFuture(product.Future, decimals, assets, et, deepCheck)
case *types.InstrumentConfigurationPerps:
return validatePerps(product.Perps, decimals, assets, et, *currentTime, deepCheck)
case *types.InstrumentConfigurationSpot:
return validateSpot(product.Spot, decimals, assets, deepCheck)
default:
return types.ProposalErrorUnsupportedProduct, ErrUnsupportedProduct
}
}
func validateLogNormalRiskParams(lnm *types.LogNormalRiskModel) (types.ProposalError, error) {
if lnm.Params == nil {
return types.ProposalErrorInvalidRiskParameter, ErrInvalidRiskParameter
}
if lnm.RiskAversionParameter.LessThan(num.DecimalFromFloat(1e-8)) || lnm.RiskAversionParameter.GreaterThan(num.DecimalFromFloat(0.1)) || // 1e-8 <= lambda <= 0.1
lnm.Tau.LessThan(num.DecimalFromFloat(1e-8)) || lnm.Tau.GreaterThan(num.DecimalOne()) || // 1e-8 <= tau <=1
lnm.Params.Mu.LessThan(num.DecimalFromFloat(-1e-6)) || lnm.Params.Mu.GreaterThan(num.DecimalFromFloat(1e-6)) || // -1e-6 <= mu <= 1e-6
lnm.Params.R.LessThan(num.DecimalFromInt64(-1)) || lnm.Params.R.GreaterThan(num.DecimalFromInt64(1)) || // -1 <= r <= 1
lnm.Params.Sigma.LessThan(num.DecimalFromFloat(1e-3)) || lnm.Params.Sigma.GreaterThan(num.DecimalFromInt64(50)) { // 1e-3 <= sigma <= 50
return types.ProposalErrorInvalidRiskParameter, ErrInvalidRiskParameter
}
return types.ProposalErrorUnspecified, nil
}
func validateRiskParameters(rp interface{}) (types.ProposalError, error) {
switch r := rp.(type) {
case *types.NewMarketConfigurationSimple:
return types.ProposalErrorUnspecified, nil
case *types.UpdateMarketConfigurationSimple:
return types.ProposalErrorUnspecified, nil
case *types.NewMarketConfigurationLogNormal:
return validateLogNormalRiskParams(r.LogNormal)
case *types.UpdateMarketConfigurationLogNormal:
return validateLogNormalRiskParams(r.LogNormal)
case *types.NewSpotMarketConfigurationLogNormal:
return validateLogNormalRiskParams(r.LogNormal)
case *types.UpdateSpotMarketConfigurationLogNormal:
return validateLogNormalRiskParams(r.LogNormal)
case nil:
return types.ProposalErrorNoRiskParameters, ErrMissingRiskParameters
default:
return types.ProposalErrorUnknownRiskParameterType, ErrUnsupportedRiskParameters
}
}
func validateLPSLAParams(slaParams *types.LiquiditySLAParams) (types.ProposalError, error) {
if slaParams == nil {
return types.ProposalErrorMissingSLAParams, fmt.Errorf("liquidity provision SLA must be provided")
}
if slaParams.PriceRange.IsZero() || slaParams.PriceRange.LessThan(num.DecimalZero()) || slaParams.PriceRange.GreaterThan(num.DecimalFromFloat(20)) {
return types.ProposalErrorInvalidSLAParams, fmt.Errorf("price range must be strictly greater than 0 and less than or equal to 20")
}
if slaParams.CommitmentMinTimeFraction.LessThan(num.DecimalZero()) || slaParams.CommitmentMinTimeFraction.GreaterThan(num.DecimalOne()) {
return types.ProposalErrorInvalidSLAParams, fmt.Errorf("commitment min time fraction must be in range [0, 1]")
}
if slaParams.SlaCompetitionFactor.LessThan(num.DecimalZero()) || slaParams.SlaCompetitionFactor.GreaterThan(num.DecimalOne()) {
return types.ProposalErrorInvalidSLAParams, fmt.Errorf("sla competition factor must be in range [0, 1]")
}
if slaParams.PerformanceHysteresisEpochs > 366 {
return types.ProposalErrorInvalidSLAParams, fmt.Errorf("provider performance hysteresis epochs must be less then 366")
}
return types.ProposalErrorUnspecified, nil
}
func validateAuctionDuration(proposedDuration time.Duration, netp NetParams) (types.ProposalError, error) {
minAuctionDuration, _ := netp.GetDuration(netparams.MarketAuctionMinimumDuration)
if proposedDuration < minAuctionDuration {
// Auction duration is too small
return types.ProposalErrorOpeningAuctionDurationTooSmall,
fmt.Errorf("proposal opening auction duration is too short, expected > %v, got %v", minAuctionDuration, proposedDuration)
}
maxAuctionDuration, _ := netp.GetDuration(netparams.MarketAuctionMaximumDuration)
if proposedDuration > maxAuctionDuration {
// Auction duration is too large
return types.ProposalErrorOpeningAuctionDurationTooLarge,
fmt.Errorf("proposal opening auction duration is too long, expected < %v, got %v", maxAuctionDuration, proposedDuration)
}
return types.ProposalErrorUnspecified, nil
}
func validateSlippageFactor(slippageFactor num.Decimal, isLinear bool) (types.ProposalError, error) {
err := types.ProposalErrorLinearSlippageOutOfRange
if !isLinear {
err = types.ProposalErrorQuadraticSlippageOutOfRange
}
if slippageFactor.IsNegative() {
return err, fmt.Errorf("proposal slippage factor has incorrect value, expected value in [0,1000000], got %s", slippageFactor.String())
}
if slippageFactor.GreaterThan(num.DecimalFromInt64(1000000)) {
return err, fmt.Errorf("proposal slippage factor has incorrect value, expected value in [0,1000000], got %s", slippageFactor.String())
}
return types.ProposalErrorUnspecified, nil
}
func validateNewSpotMarketChange(
terms *types.NewSpotMarket,
assets Assets,
deepCheck bool,
netp NetParams,
openingAuctionDuration time.Duration,
etu *enactmentTime,
) (types.ProposalError, error) {
if perr, err := validateNewInstrument(terms.Changes.Instrument, terms.Changes.DecimalPlaces, assets, etu, deepCheck, nil); err != nil {
return perr, err
}
if perr, err := validateAuctionDuration(openingAuctionDuration, netp); err != nil {
return perr, err
}
if terms.Changes.PriceMonitoringParameters != nil && len(terms.Changes.PriceMonitoringParameters.Triggers) > 5 {
return types.ProposalErrorTooManyPriceMonitoringTriggers,
fmt.Errorf("%v price monitoring triggers set, maximum allowed is 5", len(terms.Changes.PriceMonitoringParameters.Triggers) > 5)
}
if perr, err := validateRiskParameters(terms.Changes.RiskParameters); err != nil {
return perr, err
}
if perr, err := validateLPSLAParams(terms.Changes.SLAParams); err != nil {
return perr, err
}
return types.ProposalErrorUnspecified, nil
}
// ValidateNewMarket checks new market proposal terms.
func validateNewMarketChange(
terms *types.NewMarket,
assets Assets,
deepCheck bool,
netp NetParams,
openingAuctionDuration time.Duration,
etu *enactmentTime,
parent *types.Market,
currentTime time.Time,
restore bool,
) (types.ProposalError, error) {
// in all cases, the instrument must be specified and validated, successor markets included.
if perr, err := validateNewInstrument(terms.Changes.Instrument, terms.Changes.DecimalPlaces, assets, etu, deepCheck, ptr.From(currentTime)); err != nil {
return perr, err
}
// verify opening auction duration, works the same for successor markets
if perr, err := validateAuctionDuration(openingAuctionDuration, netp); !etu.cpLoad && err != nil {
return perr, err
}
// if this is a successor market, check if that's set up fine:
if perr, err := validateSuccessorMarket(terms, parent, restore); err != nil {
return perr, err
}
if perr, err := validateRiskParameters(terms.Changes.RiskParameters); err != nil {
return perr, err
}
if terms.Changes.PriceMonitoringParameters != nil && len(terms.Changes.PriceMonitoringParameters.Triggers) > 5 {
return types.ProposalErrorTooManyPriceMonitoringTriggers,
fmt.Errorf("%v price monitoring triggers set, maximum allowed is 5", len(terms.Changes.PriceMonitoringParameters.Triggers) > 5)
}
if perr, err := validateLPSLAParams(terms.Changes.LiquiditySLAParameters); err != nil {
return perr, err
}
if perr, err := validateSlippageFactor(terms.Changes.LinearSlippageFactor, true); err != nil {
return perr, err
}
if perr, err := validateSlippageFactor(terms.Changes.QuadraticSlippageFactor, false); err != nil {
return perr, err
}
return types.ProposalErrorUnspecified, nil
}
func validateSuccessorMarket(terms *types.NewMarket, parent *types.Market, restore bool) (types.ProposalError, error) {
suc := terms.Successor()
if (parent == nil && suc == nil) || (parent == nil && restore) {
return types.ProposalErrorUnspecified, nil
}
// if parent is not nil, then terms.Successor() was not nil and vice-versa. Either both are set or neither is.
if perr, err := validateInsurancePoolFraction(suc.InsurancePoolFraction); err != nil {
return perr, err
}
if perr, err := validateParentProduct(terms, parent); err != nil {
return perr, err
}
return types.ProposalErrorUnspecified, nil
}
func validateParentProduct(prop *types.NewMarket, parent *types.Market) (types.ProposalError, error) {
// make sure parent and successor are future markets
parentFuture := parent.GetFuture()
propFuture := prop.Changes.GetFuture()
if propFuture == nil || parentFuture == nil {
return types.ProposalErrorInvalidSuccessorMarket, fmt.Errorf("parent and successor markets must both be future markets")
}
if propFuture.Future.SettlementAsset != parentFuture.Future.SettlementAsset {
return types.ProposalErrorInvalidSuccessorMarket, fmt.Errorf("successor market must use asset %s", parentFuture.Future.SettlementAsset)
}
if propFuture.Future.QuoteName != parentFuture.Future.QuoteName {
return types.ProposalErrorInvalidSuccessorMarket, fmt.Errorf("successor market must use quote name %s", parentFuture.Future.QuoteName)
}
return types.ProposalErrorUnspecified, nil
}
func validateInsurancePoolFraction(frac num.Decimal) (types.ProposalError, error) {
one := num.DecimalFromInt64(1)
if frac.IsNegative() || frac.GreaterThan(one) {
return types.ProposalErrorInvalidSuccessorMarket, fmt.Errorf("insurance pool fraction should be in range 0-1, was %s", frac.String())
}
return types.ProposalErrorUnspecified, nil
}
// validateUpdateMarketChange checks market update proposal terms.
func validateUpdateSpotMarketChange(terms *types.UpdateSpotMarket) (types.ProposalError, error) {
if perr, err := validateRiskParameters(terms.Changes.RiskParameters); err != nil {
return perr, err
}
if perr, err := validateLPSLAParams(terms.Changes.SLAParams); err != nil {
return perr, err
}
return types.ProposalErrorUnspecified, nil
}
// validateUpdateMarketChange checks market update proposal terms.
func validateUpdateMarketChange(terms *types.UpdateMarket, mkt types.Market, etu *enactmentTime, currentTime time.Time) (types.ProposalError, error) {
if perr, err := validateUpdateInstrument(terms.Changes.Instrument, mkt, etu, currentTime); err != nil {
return perr, err
}
if perr, err := validateRiskParameters(terms.Changes.RiskParameters); err != nil {
return perr, err
}
if perr, err := validateLPSLAParams(terms.Changes.LiquiditySLAParameters); err != nil {
return perr, err
}
if perr, err := validateSlippageFactor(terms.Changes.LinearSlippageFactor, true); err != nil {
return perr, err
}
if perr, err := validateSlippageFactor(terms.Changes.QuadraticSlippageFactor, false); err != nil {
return perr, err
}
return types.ProposalErrorUnspecified, nil
}
func validateUpdateInstrument(instrument *types.UpdateInstrumentConfiguration, mkt types.Market, et *enactmentTime, currentTime time.Time) (types.ProposalError, error) {
switch product := instrument.Product.(type) {
case nil:
return types.ProposalErrorNoProduct, ErrMissingProduct
case *types.UpdateInstrumentConfigurationFuture:
return validateUpdateFuture(product.Future, mkt, et)
case *types.UpdateInstrumentConfigurationPerps:
return validateUpdatePerps(product.Perps, mkt, et, currentTime)
default:
return types.ProposalErrorUnsupportedProduct, ErrUnsupportedProduct
}
}
func validateUpdateFuture(future *types.UpdateFutureProduct, mkt types.Market, et *enactmentTime) (types.ProposalError, error) {
if mkt.GetFuture() == nil {
return types.ProposalErrorInvalidFutureProduct, ErrUpdateMarketDifferentProduct
}
future.DataSourceSpecForSettlementData = setDatasourceDefinitionDefaults(future.DataSourceSpecForSettlementData, et)
future.DataSourceSpecForTradingTermination = setDatasourceDefinitionDefaults(future.DataSourceSpecForTradingTermination, et)
settlData := &future.DataSourceSpecForSettlementData
if settlData == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecForSettlementData
}
if settlData.Content() == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecForSettlementData
}
ext, err := settlData.IsExternal()
if err != nil {
return types.ProposalErrorInvalidFutureProduct, err
}
if !ext {
return types.ProposalErrorInvalidFutureProduct, ErrSettlementWithInternalDataSourceIsNotAllowed
}
tterm := &future.DataSourceSpecForTradingTermination
if tterm == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecForTradingTermination
}
if tterm.Content() == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecForTradingTermination
}
tp, _ := tterm.Type()
if tp == datasource.ContentTypeInternalTimeTriggerTermination {
return types.ProposalErrorInvalidFutureProduct, ErrInternalTimeTriggerForFuturesInNotAllowed
}
filters := future.DataSourceSpecForTradingTermination.GetFilters()
for i, f := range filters {
if f.Key.Type == datapb.PropertyKey_TYPE_TIMESTAMP {
for j, cond := range f.Conditions {
v, err := strconv.ParseInt(cond.Value, 10, 64)
if err != nil {
return types.ProposalErrorInvalidFutureProduct, err
}
filters[i].Conditions[j].Value = strconv.FormatInt(v, 10)
if !et.shouldNotVerify {
if v <= et.current {
return types.ProposalErrorInvalidFutureProduct, ErrDataSourceSpecTerminationTimeBeforeEnactment
}
}
}
}
}
future.DataSourceSpecForTradingTermination.UpdateFilters(filters)
if future.DataSourceSpecBinding == nil {
return types.ProposalErrorInvalidFutureProduct, ErrMissingDataSourceSpecBinding
}
// ensure the oracle spec for settlement data can be constructed
ospec, err := spec.New(*datasource.SpecFromDefinition(future.DataSourceSpecForSettlementData))
if err != nil {
return types.ProposalErrorInvalidFutureProduct, err
}
switch future.DataSourceSpecBinding.SettlementDataProperty {
case datapb.PropertyKey_TYPE_DECIMAL.String():
err := ospec.EnsureBoundableProperty(future.DataSourceSpecBinding.SettlementDataProperty, datapb.PropertyKey_TYPE_DECIMAL)
if err != nil {
return types.ProposalErrorInvalidFutureProduct, fmt.Errorf("invalid oracle spec binding for settlement data: %w", err)
}
default:
err := ospec.EnsureBoundableProperty(future.DataSourceSpecBinding.SettlementDataProperty, datapb.PropertyKey_TYPE_INTEGER)
if err != nil {
return types.ProposalErrorInvalidFutureProduct, fmt.Errorf("invalid oracle spec binding for settlement data: %w", err)
}
}
// ensure the oracle spec for market termination can be constructed
ospec, err = spec.New(*datasource.SpecFromDefinition(future.DataSourceSpecForTradingTermination))
if err != nil {
return types.ProposalErrorInvalidFutureProduct, err
}
switch future.DataSourceSpecBinding.TradingTerminationProperty {
case spec.BuiltinTimestamp:
if err := ospec.EnsureBoundableProperty(future.DataSourceSpecBinding.TradingTerminationProperty, datapb.PropertyKey_TYPE_TIMESTAMP); err != nil {
return types.ProposalErrorInvalidFutureProduct, fmt.Errorf("invalid oracle spec binding for trading termination: %w", err)
}
default:
if err := ospec.EnsureBoundableProperty(future.DataSourceSpecBinding.TradingTerminationProperty, datapb.PropertyKey_TYPE_BOOLEAN); err != nil {
return types.ProposalErrorInvalidFutureProduct, fmt.Errorf("invalid oracle spec binding for trading termination: %w", err)
}
}
return types.ProposalErrorUnspecified, nil
}
func validateUpdatePerps(perps *types.UpdatePerpsProduct, mkt types.Market, et *enactmentTime, currentTime time.Time) (types.ProposalError, error) {
if mkt.GetPerps() == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrUpdateMarketDifferentProduct
}
perps.DataSourceSpecForSettlementData = setDatasourceDefinitionDefaults(perps.DataSourceSpecForSettlementData, et)
perps.DataSourceSpecForSettlementSchedule = setDatasourceDefinitionDefaults(perps.DataSourceSpecForSettlementSchedule, et)
settlData := &perps.DataSourceSpecForSettlementData
if settlData == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecForSettlementData
}
if settlData.Content() == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecForSettlementData
}
ext, err := settlData.IsExternal()
if err != nil {
return types.ProposalErrorInvalidPerpsProduct, err
}
if !ext {
return types.ProposalErrorInvalidPerpsProduct, ErrSettlementWithInternalDataSourceIsNotAllowed
}
settlSchedule := &perps.DataSourceSpecForSettlementSchedule
if settlSchedule == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecForSettlementSchedule
}
if settlSchedule.Content() == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecForSettlementSchedule
}
if perps.DataSourceSpecBinding == nil {
return types.ProposalErrorInvalidPerpsProduct, ErrMissingDataSourceSpecBinding
}
// ensure the oracle spec for settlement data can be constructed
ospec, err := spec.New(*datasource.SpecFromDefinition(perps.DataSourceSpecForSettlementData))
if err != nil {
return types.ProposalErrorInvalidPerpsProduct, err
}
switch perps.DataSourceSpecBinding.SettlementDataProperty {
case datapb.PropertyKey_TYPE_DECIMAL.String():
err := ospec.EnsureBoundableProperty(perps.DataSourceSpecBinding.SettlementDataProperty, datapb.PropertyKey_TYPE_DECIMAL)
if err != nil {
return types.ProposalErrorInvalidPerpsProduct, fmt.Errorf("invalid oracle spec binding for settlement data: %w", err)
}
default:
err := ospec.EnsureBoundableProperty(perps.DataSourceSpecBinding.SettlementDataProperty, datapb.PropertyKey_TYPE_INTEGER)
if err != nil {
return types.ProposalErrorInvalidPerpsProduct, fmt.Errorf("invalid oracle spec binding for settlement data: %w", err)
}
}
// ensure the oracle spec for market termination can be constructed
ospec, err = spec.New(*datasource.SpecFromDefinition(perps.DataSourceSpecForSettlementSchedule))
if err != nil {
return types.ProposalErrorInvalidPerpsProduct, err