@@ -19,13 +19,13 @@ import (
19
19
20
20
func checkFeeds (c * grogucontext.Context ) {
21
21
// Fetch parameters, supported feeds, validator prices, and prices
22
- params , feeds , validatorPrices , prices , err := fetchData (c )
22
+ params , feeds , validatorPrices , _ , err := fetchData (c )
23
23
if err != nil {
24
24
return
25
25
}
26
26
27
27
signalIDTimestampMap := convertToSignalIDTimestampMap (validatorPrices )
28
- signalIDChainPriceMap := convertToSignalIDChainPriceMap ( prices )
28
+ signalIDValidatorPriceMap := convertToSignalIDValidatorPriceMap ( validatorPrices )
29
29
30
30
requestedSignalIDs := make (map [string ]time.Time )
31
31
now := time .Now ()
@@ -60,7 +60,7 @@ func checkFeeds(c *grogucontext.Context) {
60
60
c .Config .DistributionStartPercentage ,
61
61
)
62
62
63
- if assignedTime .Before (now ) || isDeviate (c , feed , signalIDChainPriceMap ) {
63
+ if assignedTime .Before (now ) || isDeviate (c , feed , signalIDValidatorPriceMap ) {
64
64
updateRequestedSignalID (c , requestedSignalIDs , feed , timestamp , params )
65
65
}
66
66
}
@@ -141,11 +141,11 @@ func calculateAssignedTime(
141
141
return time .Unix (timestamp + 2 , 0 ).Add (time .Duration (timeOffset ) * time .Second )
142
142
}
143
143
144
- // isDeviate checks if the current price is deviated from the on-chain price
144
+ // isDeviate checks if the current price is deviated from the on-chain validator price
145
145
func isDeviate (
146
146
c * grogucontext.Context ,
147
147
feed types.Feed ,
148
- signalIDChainPriceMap map [string ]uint64 ,
148
+ signalIDValidatorPriceMap map [string ]uint64 ,
149
149
) bool {
150
150
currentPrices , err := c .PriceService .Query ([]string {feed .SignalID })
151
151
if err != nil || len (currentPrices ) == 0 ||
@@ -158,8 +158,12 @@ func isDeviate(
158
158
return false
159
159
}
160
160
161
+ if signalIDValidatorPriceMap [feed .SignalID ] == 0 {
162
+ return true
163
+ }
164
+
161
165
return feed .DeviationInThousandth <= deviationInThousandth (
162
- signalIDChainPriceMap [feed .SignalID ],
166
+ signalIDValidatorPriceMap [feed .SignalID ],
163
167
uint64 (price * math .Pow10 (9 )),
164
168
)
165
169
}
@@ -189,15 +193,15 @@ func convertToSignalIDTimestampMap(data []types.ValidatorPrice) map[string]int64
189
193
return signalIDTimestampMap
190
194
}
191
195
192
- // convertToSignalIDChainPriceMap converts an array of Prices to a map of signal id to its on-chain prices.
193
- func convertToSignalIDChainPriceMap (data []* types.Price ) map [string ]uint64 {
194
- signalIDChainPriceMap := make (map [string ]uint64 )
196
+ // convertToSignalIDValidatorPriceMap converts an array of Prices to a map of signal id to its on-chain validator prices.
197
+ func convertToSignalIDValidatorPriceMap (data []types.ValidatorPrice ) map [string ]uint64 {
198
+ signalIDValidatorPriceMap := make (map [string ]uint64 )
195
199
196
200
for _ , entry := range data {
197
- signalIDChainPriceMap [entry .SignalID ] = entry .Price
201
+ signalIDValidatorPriceMap [entry .SignalID ] = entry .Price
198
202
}
199
203
200
- return signalIDChainPriceMap
204
+ return signalIDValidatorPriceMap
201
205
}
202
206
203
207
// deviationInThousandth calculates the deviation in thousandth between two values.
0 commit comments