Skip to content

Commit

Permalink
fix: mergedPFVersion for chainlink/composite pf
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-98 committed Feb 17, 2024
1 parent 1e7b0bf commit d28a2d4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions ds/mergedPFVersion.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ func (mdl *MergedPFManager) Load(details core.Json, discoveredAt int64) {

func (mdl MergedPFManager) Save(details *core.Json) {
(*details)["mergedPFVersion"] = mdl
log.Info((*details)["mergedPFVersion"])
// log.Info(utils.ToJson((*details)["mergedPFVersion"]))
}

func (mdl MergedPFManager) GetMergedPFVersion(blockNum int64) schemas.MergedPFVersion {
func (mdl MergedPFManager) GetMergedPFVersion(blockNum int64, syncAdapterAddr string) schemas.MergedPFVersion {
for _, entry := range mdl {
if entry.BlockNumber <= blockNum {
return entry.MergedPFVersion
}
}
log.Fatal("Can't get mergedPFVersion", mdl)
log.Fatal("Can't get mergedPFVersion", mdl, blockNum, syncAdapterAddr)
return schemas.MergedPFVersion(0)
}
func (mdl *MergedPFManager) AddToken(token string, blockNum int64, pfVersion schemas.PFVersion) {
Expand Down
2 changes: 1 addition & 1 deletion models/chainlink_price_feed/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func NewChainlinkPriceFeedFromAdapter(adapter *ds.SyncAdapter, includeLastLogBef
}
obj.DataProcessType = ds.ViaMultipleLogs
obj.mergedPFManager = &ds.MergedPFManager{}
obj.mergedPFManager.Load(obj.Details, obj.DiscoveredAt)
obj.mergedPFManager.Load(obj.Details, obj.FirstLogAt)
return obj
}

Expand Down
4 changes: 2 additions & 2 deletions models/chainlink_price_feed/on_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (mdl *ChainlinkPriceFeed) OnLogs(txLogs []types.Log) {
RoundId: roundId,
PriceBI: (*core.BigInt)(answerBI),
Price: utils.GetFloat64Decimal(answerBI, pfVersion.Decimals()),
MergedPFVersion: mdl.mergedPFManager.GetMergedPFVersion(blockNum),
MergedPFVersion: mdl.mergedPFManager.GetMergedPFVersion(blockNum, mdl.Address),
}
mdl.Repo.AddPriceFeed(priceFeed)
blockNums = append(blockNums, blockNum)
Expand All @@ -77,7 +77,7 @@ func (mdl *ChainlinkPriceFeed) AddToken(token string, blockNum int64, pfVersion

func (mdl ChainlinkPriceFeed) DisableToken(token string, blockNum int64, pfVersion schemas.PFVersion) {
mdl.mergedPFManager.DisableToken(token, blockNum, pfVersion)
final := mdl.mergedPFManager.GetMergedPFVersion(blockNum)
final := mdl.mergedPFManager.GetMergedPFVersion(blockNum, mdl.Address)
if final == 0 {
mdl.SetBlockToDisableOn(blockNum)
}
Expand Down
3 changes: 2 additions & 1 deletion models/chainlink_price_feed/on_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ func TestOnLogs(t *testing.T) {
Contract: &schemas.Contract{
Address: validPf.Feed,
DiscoveredAt: 1,
FirstLogAt: 1,
},
V: core.NewVersion(1),
Details: core.Json{"token": validPf.Token, "mergedPFVersion": validPf.MergedPFVersion},
},
}, mergedPFManager: &ds.MergedPFManager{}}
obj.mergedPFManager.Load(obj.Details, obj.DiscoveredAt)
obj.mergedPFManager.Load(obj.Details, obj.FirstLogAt)
txLogs := []types.Log{
{
BlockNumber: 1,
Expand Down
2 changes: 1 addition & 1 deletion models/composite_chainlink/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func NewCompositeChainlinkPFFromAdapter(adapter *ds.SyncAdapter) *CompositeChain
compositeMdl.setPrices(adapter.LastSync)
//
compositeMdl.mergedPFManager = &ds.MergedPFManager{}
compositeMdl.mergedPFManager.Load(compositeMdl.Details, compositeMdl.DiscoveredAt)
compositeMdl.mergedPFManager.Load(compositeMdl.Details, compositeMdl.FirstLogAt)
return compositeMdl
}

Expand Down
4 changes: 2 additions & 2 deletions models/composite_chainlink/on_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (mdl *CompositeChainlinkPF) addPriceToDB(blockNum int64) {
RoundId: 0,
PriceBI: (*core.BigInt)(answerBI),
Price: utils.GetFloat64Decimal(answerBI, 8),
MergedPFVersion: mdl.mergedPFManager.GetMergedPFVersion(blockNum),
MergedPFVersion: mdl.mergedPFManager.GetMergedPFVersion(blockNum, mdl.Address),
}
mdl.Repo.AddPriceFeed(priceFeed)
}
Expand All @@ -128,7 +128,7 @@ func (mdl *CompositeChainlinkPF) AddToken(token string, blockNum int64, pfVersio

func (mdl CompositeChainlinkPF) DisableToken(token string, blockNum int64, pfVersion schemas.PFVersion) {
mdl.mergedPFManager.DisableToken(token, blockNum, pfVersion)
final := mdl.mergedPFManager.GetMergedPFVersion(blockNum)
final := mdl.mergedPFManager.GetMergedPFVersion(blockNum, mdl.Address)
if final == 0 {
mdl.SetBlockToDisableOn(blockNum)
}
Expand Down

0 comments on commit d28a2d4

Please sign in to comment.