Skip to content

Commit

Permalink
deviations config switch (#115)
Browse files Browse the repository at this point in the history
* deviations config switch

* logs modifications

* msg generation config check
  • Loading branch information
dixitaniket authored Jun 7, 2023
1 parent 1a1f71a commit 5418701
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions cw-relayer/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,29 +232,29 @@ func (r *Relayer) setDenomPrices(ctx context.Context, postMedian bool) error {
var mu sync.Mutex
g, _ := errgroup.WithContext(ctx)

g.Go(func() error {
deviationsQueryResponse, err := queryClient.MedianDeviations(ctx, &oracletypes.QueryMedianDeviations{})
if err != nil {
return err
}
if postMedian {
g.Go(func() error {
deviationsQueryResponse, err := queryClient.MedianDeviations(ctx, &oracletypes.QueryMedianDeviations{})
if err != nil {
return err
}

if len(deviationsQueryResponse.MedianDeviations) == 0 {
return fmt.Errorf("median deviations empty")
}
if len(deviationsQueryResponse.MedianDeviations) == 0 {
return fmt.Errorf("median deviations empty")
}

deviations := make([]types.DecCoin, len(deviationsQueryResponse.MedianDeviations))
for i, priceStamp := range deviationsQueryResponse.MedianDeviations {
deviations[i] = *priceStamp.ExchangeRate
}
deviations := make([]types.DecCoin, len(deviationsQueryResponse.MedianDeviations))
for i, priceStamp := range deviationsQueryResponse.MedianDeviations {
deviations[i] = *priceStamp.ExchangeRate
}

mu.Lock()
r.historicalDeviations = deviations
mu.Unlock()
mu.Lock()
r.historicalDeviations = deviations
mu.Unlock()

return nil
})
return nil
})

if postMedian {
g.Go(func() error {
medianQueryResponse, err := queryClient.Medians(ctx, &oracletypes.QueryMedians{})
if err != nil {
Expand Down Expand Up @@ -322,35 +322,35 @@ func (r *Relayer) tick(ctx context.Context) error {
return err
}

deviationMsg, err := genRateMsgData(forceRelay, RelayHistoricalDeviation, r.deviationRequestID, nextBlockTime, r.historicalDeviations)
if err != nil {
return err
}

var msgs []types.Msg
msgs = append(msgs, r.genWasmMsg(exchangeMsg), r.genWasmMsg(deviationMsg))
msgs = append(msgs, r.genWasmMsg(exchangeMsg))

if postMedian {
deviationMsg, err := genRateMsgData(forceRelay, RelayHistoricalDeviation, r.deviationRequestID, nextBlockTime, r.historicalDeviations)
if err != nil {
return err
}

resolveTime := time.Duration(r.resolveDuration.Nanoseconds() * r.medianDuration)
nextMedianBlockTime := blockTimestamp.Add(resolveTime).Unix()
medianMsg, err := genRateMsgData(forceRelay, RelayHistoricalMedian, r.medianRequestID, nextMedianBlockTime, r.historicalMedians)
if err != nil {
return err
}

msgs = append(msgs, r.genWasmMsg(medianMsg))
msgs = append(msgs, r.genWasmMsg(medianMsg), r.genWasmMsg(deviationMsg))
}

logs := r.logger.Info()
logs.Str("contract address", r.contractAddress).
Str("relayer address", r.relayerClient.RelayerAddrString).
Str("block timestamp", blockTimestamp.String()).
Bool("median posted", postMedian).
Uint64("request id", r.requestID).
Uint64("deviation request id", r.deviationRequestID)
Uint64("request id", r.requestID)

if postMedian {
logs.Uint64("median request id", r.medianRequestID)
logs.Uint64("median request id", r.medianRequestID).
Uint64("deviation request id", r.deviationRequestID)
}

logs.Msg("broadcasting execute to contract")
Expand All @@ -367,8 +367,8 @@ func (r *Relayer) tick(ctx context.Context) error {

// increment request id to be stored in contracts
r.requestID += 1
r.deviationRequestID += 1
if postMedian {
r.deviationRequestID += 1
r.medianRequestID += 1
}

Expand Down

0 comments on commit 5418701

Please sign in to comment.