Skip to content

Commit

Permalink
fix: get prices
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-98 committed Nov 11, 2024
1 parent 874ab8f commit 8388d60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package composite_redstone_price_feed

import (
"math/big"
"time"

"github.com/Gearbox-protocol/sdk-go/artifacts/multicall"
"github.com/Gearbox-protocol/sdk-go/core"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (mdl *CompositeRedStonePriceFeed) GetCalls(blockNum int64) (calls []multica
return []multicall.Multicall2Call{{
Target: common.HexToAddress(mdl.Address),
CallData: data,
},{
}, {
Target: mdl.priceFeed1,
CallData: data,
}}, true
Expand All @@ -64,14 +65,14 @@ func (mdl *CompositeRedStonePriceFeed) ProcessResult(blockNum int64, results []m
if results[0].Success {
value, err := core.GetAbi("YearnPriceFeed").Unpack("latestRoundData", results[0].ReturnData)
log.CheckFatal(err)
price := *abi.ConvertType(value[1], new(*big.Int)).(**big.Int)
price := *abi.ConvertType(value[1], new(*big.Int)).(**big.Int)
log.Info("onchain price found for ", mdl.Address, "at", blockNum, price)
return parsePriceForRedStone(price, isPriceInUSD)
// } else if time.Since(time.Unix(int64(mdl.Repo.SetAndGetBlock(blockNum).Timestamp),0)) > time.Hour {
} else {
if (len(force) ==0 || !force[0] ) {
return nil
}
} else if time.Since(time.Unix(int64(mdl.Repo.SetAndGetBlock(blockNum).Timestamp), 0)) > time.Hour {
// } else {
// if len(force) == 0 || !force[0] {
// return nil
// }
}
}
validTokens := mdl.TokensValidAtBlock(blockNum)
Expand Down
19 changes: 10 additions & 9 deletions models/aggregated_block_feed/redstone_price_feed/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redstone_price_feed
import (
"encoding/hex"
"math/big"
"time"

"github.com/Gearbox-protocol/sdk-go/artifacts/multicall"
"github.com/Gearbox-protocol/sdk-go/core"
Expand Down Expand Up @@ -31,10 +32,10 @@ func NewRedstonePriceFeedFromAdapter(adapter *ds.SyncAdapter) *RedstonePriceFeed
}

func (obj *RedstonePriceFeed) GetCalls(blockNum int64) (calls []multicall.Multicall2Call, isQueryable bool) {
data, _:=hex.DecodeString("feaf968c")
data, _ := hex.DecodeString("feaf968c")
return []multicall.Multicall2Call{
{
Target: common.HexToAddress(obj.Address),
Target: common.HexToAddress(obj.Address),
CallData: data,
},
}, true
Expand All @@ -50,14 +51,14 @@ func (mdl *RedstonePriceFeed) ProcessResult(blockNum int64, results []multicall.
if results[0].Success {
value, err := core.GetAbi("YearnPriceFeed").Unpack("latestRoundData", results[0].ReturnData)
log.CheckFatal(err)
price := *abi.ConvertType(value[1], new(*big.Int)).(**big.Int)
price := *abi.ConvertType(value[1], new(*big.Int)).(**big.Int)
log.Info("onchain price found for ", mdl.Address, "at", blockNum, price)
return parsePriceForRedStone(price, isPriceInUSD)
// } else if time.Since(time.Unix(int64(mdl.Repo.SetAndGetBlock(blockNum).Timestamp),0)) > time.Hour {
} else {
if (len(force) ==0 || !force[0] ) {
return nil
}
} else if time.Since(time.Unix(int64(mdl.Repo.SetAndGetBlock(blockNum).Timestamp), 0)) > time.Hour {
// } else {
// if (len(force) ==0 || !force[0] ) {
// return nil
// }
}
}
{
Expand All @@ -67,7 +68,7 @@ func (mdl *RedstonePriceFeed) ProcessResult(blockNum int64, results []multicall.
log.Warnf("RedStone price for %s at %d is %f", mdl.Repo.GetToken(validTokens[0].Token).Symbol, blockNum, priceBI)
return nil
}

priceData := parsePriceForRedStone(priceBI, isPriceInUSD)
log.Infof("RedStone price for %s at %d is %f", mdl.Repo.GetToken(validTokens[0].Token).Symbol, blockNum, priceData.Price)
//
Expand Down

0 comments on commit 8388d60

Please sign in to comment.