Skip to content

Commit

Permalink
fix: force get price in redstone and composite oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-98 committed Sep 2, 2024
1 parent 8a2ed19 commit 7152ec0
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ParseQueryRoundData(returnData []byte, isPriceInUSD bool, feed string, bloc
}
}

func (mdl *BasePriceFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result) *schemas.PriceFeed {
func (mdl *BasePriceFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result, force ...bool) *schemas.PriceFeed {
isPriceInUSD := mdl.GetVersion().IsPriceInUSD()
if !results[0].Success {
if mdl.GetVersion().MoreThanEq(core.NewVersion(300)) {
Expand Down
2 changes: 1 addition & 1 deletion models/aggregated_block_feed/base_price_feed/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type QueryPriceFeedI interface {
GetPFType() string
ds.SyncAdapterI
GetCalls(blockNum int64) (calls []multicall.Multicall2Call, isQueryable bool)
ProcessResult(blockNum int64, results []multicall.Multicall2Result) *schemas.PriceFeed
ProcessResult(blockNum int64, results []multicall.Multicall2Result, force ...bool) *schemas.PriceFeed
DisableToken(token string, disabledAt int64, pfVersion schemas.PFVersion)
AddToken(token string, discoveredAt int64, pfVersion schemas.PFVersion)
GetTokens() map[string]map[schemas.PFVersion][]int64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (mdl *CompositeRedStonePriceFeed) GetCalls(blockNum int64) (calls []multica
}}, true
}

func (mdl *CompositeRedStonePriceFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result) *schemas.PriceFeed {
func (mdl *CompositeRedStonePriceFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result, force ...bool) *schemas.PriceFeed {
if !results[1].Success {
return nil
}
Expand All @@ -69,7 +69,9 @@ func (mdl *CompositeRedStonePriceFeed) ProcessResult(blockNum int64, results []m
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 {
return nil
if (len(force) ==0 || !force[0] ) {
return nil
}
}
}
validTokens := mdl.TokensValidAtBlock(blockNum)
Expand Down
2 changes: 1 addition & 1 deletion models/aggregated_block_feed/curve_price_feed/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewCurvePriceFeedFromAdapter(adapter *ds.SyncAdapter) *CurvePriceFeed {

var curvePFLatestRoundDataTimer = map[string]log.TimerFn{}

func (adapter *CurvePriceFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result) *schemas.PriceFeed {
func (adapter *CurvePriceFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result, force ...bool) *schemas.PriceFeed {
if !results[0].Success {
if adapter.GetVersion().LessThan(core.NewVersion(300)) { // failed and
// if virtualprice of pool for this oracle is not within lowerBound and upperBound , ignore the price
Expand Down
6 changes: 4 additions & 2 deletions models/aggregated_block_feed/redstone_price_feed/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (obj *RedstonePriceFeed) GetCalls(blockNum int64) (calls []multicall.Multic
}, true
}

func (mdl *RedstonePriceFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result) *schemas.PriceFeed {
func (mdl *RedstonePriceFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result, force ...bool) *schemas.PriceFeed {
validTokens := mdl.TokensValidAtBlock(blockNum)
isPriceInUSD := mdl.GetVersion().IsPriceInUSD()
{
Expand All @@ -55,7 +55,9 @@ func (mdl *RedstonePriceFeed) ProcessResult(blockNum int64, results []multicall.
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 {
return nil
if (len(force) ==0 || !force[0] ) {
return nil
}
}
}
{
Expand Down
2 changes: 1 addition & 1 deletion models/aggregated_block_feed/yearn_price_feed/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewYearnPriceFeedFromAdapter(adapter *ds.SyncAdapter) *YearnPriceFeed {
// same as query price feed
// func (*YearnPriceFeed) GetCalls(blockNum int64) (calls []multicall.Multicall2Call, isQueryable bool) {

func (mdl *YearnPriceFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result) *schemas.PriceFeed {
func (mdl *YearnPriceFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result, force ...bool) *schemas.PriceFeed {
if !results[0].Success {
if utils.Contains([]string{
"0x628539959F3B3bb0cFe2102dCaa659cf1E8D19EB",
Expand Down
2 changes: 1 addition & 1 deletion repository/handlers/treasury/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (repo TreasuryRepo) GetRedStonePrice(blockNum int64, oracle, token string)
return nil
}
results := core.MakeMultiCall(repo.client, blockNum, false, call)
price := adapter.ProcessResult(blockNum, results)
price := adapter.ProcessResult(blockNum, results, true)
return price.PriceBI.Convert()
}
return nil
Expand Down

0 comments on commit 7152ec0

Please sign in to comment.