Skip to content

Commit

Permalink
fix: composite pf's pf0 can be chainlink, redstone or native-redstone
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-98 committed Jul 4, 2024
1 parent 192f83d commit aaae9a8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
6 changes: 5 additions & 1 deletion debts/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,11 @@ func (eng *DebtEngine) CalculateSessionDebt(blockNum int64, session *schemas.Cre
// log.Info(debt.CalHealthFactor, sessionSnapshot.HealthFactor, blockNum)
// log.Info(debt.CalTotalValueBI, sessionSnapshot.TotalValueBI, blockNum)
if log.GetBaseNet(core.GetChainId(eng.client)) == "ARBITRUM" {
// ignore // TODO:FIX
profile.CumIndexAndUToken = cumIndexAndUToken
profile.Debt = debt
profile.CreditSessionSnapshot = sessionSnapshot
profile.UnderlyingDecimals = cumIndexAndUToken.Decimals
log.Warn(utils.ToJson(profile))
} else if eng.hasRedStoneToken(sessionSnapshot.Balances) {
if IsChangeMoreThanFraction(debt.CalTotalValueBI, sessionSnapshot.TotalValueBI, big.NewFloat(0.003)) { // .3% allowed
notMatched = true
Expand Down
17 changes: 15 additions & 2 deletions models/price_oracle/on_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,21 @@ func (mdl *PriceOracle) V3PriceFeedType(opts *bind.CallOpts, oracle, token strin
pf0Type := func() int {
pf0Type, err := core.CallFuncWithExtraBytes(mdl.Client, "3fd0875f", pf, 0, nil) // priceFeedType
if err != nil { // this means that it can be from outside of gearbox protocol, like redstone own oracle.
log.Warnf("pf:%s oracle:%s token:%s err:%s, pf0 can be non-gearbox oracle.", pf, oracle, token, err)
return core.V3_CURVE_2LP_ORACLE
pf0Type := func() int {
con, err := priceFeed.NewPriceFeed(pf, mdl.Client)
log.CheckFatal(err)
_, err1 := con.PhaseId(nil)
if err1 == nil {
return core.V3_CHAINLINK_ORACLE
}
_, err2 := con.Aggregator(nil)
if err2 == nil {
return core.V3_CHAINLINK_ORACLE
}
return core.V3_CURVE_2LP_ORACLE
}()
log.Warnf("pf:%s oracle:%s token:%s err:%s, pf0 can be non-gearbox oracle or chainlink. assumed type of pf0.: %d", pf, oracle, token, err, pf0Type)
return pf0Type
}
return int(new(big.Int).SetBytes(pf0Type).Int64())
}()
Expand Down
4 changes: 3 additions & 1 deletion repository/handlers/prev_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ func (repo *PrevPriceStore) isPFAdded(pf *schemas.PriceFeed) bool {
if oldPF.BlockNumber >= pf.BlockNumber && // if old pf has block number more than new pf
!(pf.Price == 0 || pf.Price == 100) && // and new pf price is not 0 or 100
!(oldPF.Price == 0 || oldPF.Price == 100) { // and old pf price is not 0 or 100
log.Fatalf("oldPF %s.\n NewPF %s.", oldPF, pf)
if !(pf.Token == "0x2416092f143378750bb29b79eD961ab195CcEea5" && oldPF.BlockNumber == 228761216) { // for ezETH on arbitrum
log.Fatalf("oldPF %s.\n NewPF %s.", oldPF, pf)
}
}
// if the blocknum of new price is less than previous seenly price , ignore
// same price then don't add
Expand Down

0 comments on commit aaae9a8

Please sign in to comment.