Skip to content

Commit

Permalink
feat: getToken for chainlink/composite oracle shouldn't fail
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-98 committed Mar 7, 2024
1 parent 12fe4f1 commit 73ae1ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
17 changes: 12 additions & 5 deletions ds/mergedPFVersion.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ds

import (
"fmt"
"reflect"

"github.com/Gearbox-protocol/sdk-go/core"
Expand Down Expand Up @@ -89,14 +90,20 @@ func (mdl MergedPFManager) Save(details *core.Json) {
}

func (mdl MergedPFManager) GetMergedPFVersion(token string, blockNum int64, syncAdapterAddr string) schemas.MergedPFVersion {
version, err := mdl.getMergedPFVersion(token, blockNum, syncAdapterAddr)
log.CheckFatal(err)
return version
}

func (mdl MergedPFManager) getMergedPFVersion(token string, blockNum int64, syncAdapterAddr string) (schemas.MergedPFVersion, error) {
for ind := len(mdl[token]) - 1; ind >= 0; ind-- {
if mdl[token][ind].BlockNumber <= blockNum {
return mdl[token][ind].MergedPFVersion
return mdl[token][ind].MergedPFVersion, nil
}
}
log.Fatal("Can't get mergedPFVersion", mdl, blockNum, syncAdapterAddr)
return schemas.MergedPFVersion(0)
return schemas.MergedPFVersion(0), fmt.Errorf("can't get mergedPFVersion %v at %d for adapter: %s", mdl, blockNum, syncAdapterAddr)
}

func (mdl MergedPFManager) AddToken(token string, blockNum int64, pfVersion schemas.PFVersion) {
var last schemas.MergedPFVersion
if len(mdl[token]) != 0 {
Expand All @@ -110,8 +117,8 @@ func (mdl MergedPFManager) AddToken(token string, blockNum int64, pfVersion sche
}
func (mdl MergedPFManager) GetTokens(blockNum int64) (tokens []string) {
for token := range mdl {
version := mdl.GetMergedPFVersion(token, blockNum, "")
if version != 0 {
version, err := mdl.getMergedPFVersion(token, blockNum, "")
if version != 0 && err == nil {
tokens = append(tokens, token)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (mdl *QueryPriceFeed) AddToken(token string, discoveredAt int64, pfVersion
func (mdl *QueryPriceFeed) DisableToken(token string, disabledAt int64, pfVersion schemas.PFVersion) {
tokenDetails := mdl.DetailsDS.Tokens[token]
if tokenDetails == nil || len(tokenDetails[pfVersion]) != 1 {
log.Fatalf("%s's enable block number for pfVersion %d is malformed: %v", token, pfVersion, tokenDetails)
log.Fatalf("%s's enable block number for pfVersion %d is malformed: %v, trying with new block: %d", token, pfVersion, tokenDetails, disabledAt)
}
tokenDetails[pfVersion] = append(tokenDetails[pfVersion], disabledAt)
}
Expand Down
1 change: 1 addition & 0 deletions models/chainlink_price_feed/on_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (mdl *ChainlinkPriceFeed) OnLogs(txLogs []types.Log) {
if txLogInd+1 < len(txLogs) && int64(txLogs[txLogInd+1].BlockNumber) == blockNum {
continue
}
// has atleast one valid token.
if mdl.mergedPFManager.GetTokens(blockNum)[0] == "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" &&
mdl.Address == "0x37bC7498f4FF12C19678ee8fE19d713b87F6a9e6" && blockNum > 17217055 { // as there is already another chainlink activated 0xE62B71cf983019BFf55bC83B48601ce8419650CC
continue
Expand Down

0 comments on commit 73ae1ce

Please sign in to comment.