Skip to content

Commit 4db8516

Browse files
authored
[Feeds] Hotfix deviation grogu (compare their own price) (#152)
* hotfix to compare deviation from own price * prevent price zero case
1 parent 0acc4ac commit 4db8516

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

grogu/feed/check.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import (
1919

2020
func checkFeeds(c *grogucontext.Context) {
2121
// Fetch parameters, supported feeds, validator prices, and prices
22-
params, feeds, validatorPrices, prices, err := fetchData(c)
22+
params, feeds, validatorPrices, _, err := fetchData(c)
2323
if err != nil {
2424
return
2525
}
2626

2727
signalIDTimestampMap := convertToSignalIDTimestampMap(validatorPrices)
28-
signalIDChainPriceMap := convertToSignalIDChainPriceMap(prices)
28+
signalIDValidatorPriceMap := convertToSignalIDValidatorPriceMap(validatorPrices)
2929

3030
requestedSignalIDs := make(map[string]time.Time)
3131
now := time.Now()
@@ -60,7 +60,7 @@ func checkFeeds(c *grogucontext.Context) {
6060
c.Config.DistributionStartPercentage,
6161
)
6262

63-
if assignedTime.Before(now) || isDeviate(c, feed, signalIDChainPriceMap) {
63+
if assignedTime.Before(now) || isDeviate(c, feed, signalIDValidatorPriceMap) {
6464
updateRequestedSignalID(c, requestedSignalIDs, feed, timestamp, params)
6565
}
6666
}
@@ -141,11 +141,11 @@ func calculateAssignedTime(
141141
return time.Unix(timestamp+2, 0).Add(time.Duration(timeOffset) * time.Second)
142142
}
143143

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
145145
func isDeviate(
146146
c *grogucontext.Context,
147147
feed types.Feed,
148-
signalIDChainPriceMap map[string]uint64,
148+
signalIDValidatorPriceMap map[string]uint64,
149149
) bool {
150150
currentPrices, err := c.PriceService.Query([]string{feed.SignalID})
151151
if err != nil || len(currentPrices) == 0 ||
@@ -158,8 +158,12 @@ func isDeviate(
158158
return false
159159
}
160160

161+
if signalIDValidatorPriceMap[feed.SignalID] == 0 {
162+
return true
163+
}
164+
161165
return feed.DeviationInThousandth <= deviationInThousandth(
162-
signalIDChainPriceMap[feed.SignalID],
166+
signalIDValidatorPriceMap[feed.SignalID],
163167
uint64(price*math.Pow10(9)),
164168
)
165169
}
@@ -189,15 +193,15 @@ func convertToSignalIDTimestampMap(data []types.ValidatorPrice) map[string]int64
189193
return signalIDTimestampMap
190194
}
191195

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)
195199

196200
for _, entry := range data {
197-
signalIDChainPriceMap[entry.SignalID] = entry.Price
201+
signalIDValidatorPriceMap[entry.SignalID] = entry.Price
198202
}
199203

200-
return signalIDChainPriceMap
204+
return signalIDValidatorPriceMap
201205
}
202206

203207
// deviationInThousandth calculates the deviation in thousandth between two values.

0 commit comments

Comments
 (0)