55
66 "github.com/Gearbox-protocol/sdk-go/core"
77 "github.com/Gearbox-protocol/sdk-go/log"
8+ "github.com/Gearbox-protocol/sdk-go/pkg"
89 "github.com/Gearbox-protocol/sdk-go/pkg/dc"
910 "github.com/Gearbox-protocol/sdk-go/pkg/redstone"
1011
@@ -13,7 +14,7 @@ import (
1314 "github.com/ethereum/go-ethereum/common"
1415)
1516
16- func (mdl * CommonCMAdapter ) priceFeedNeeded (balances core.DBBalanceFormat ) (ans []core.RedStonePF ) {
17+ func (mdl * CommonCMAdapter ) priceFeedNeededRedStone (balances core.DBBalanceFormat ) (ans []core.RedStonePF ) {
1718 pool := mdl .State .PoolAddress
1819 priceOracle := mdl .Repo .GetAdapter (pool ).(* pool_v3.Poolv3 ).State .PriceOracle
1920 feeds := mdl .Repo .GetMainTokenOracles ()[priceOracle ]
@@ -37,13 +38,40 @@ func (mdl *CommonCMAdapter) priceFeedNeeded(balances core.DBBalanceFormat) (ans
3738 }
3839 return
3940}
41+
42+ func (mdl * CommonCMAdapter ) priceFeedPyth (balances core.DBBalanceFormat , blockNum int64 ) (ans []redstone.PytDataWithFeed ) {
43+ pool := mdl .State .PoolAddress
44+ priceOracle := mdl .Repo .GetAdapter (pool ).(* pool_v3.Poolv3 ).State .PriceOracle
45+ feeds := mdl .Repo .GetMainTokenOracles ()[priceOracle ]
46+ ts := mdl .Repo .SetAndGetBlock (blockNum ).Timestamp
47+ for token , bal := range balances {
48+ {
49+ d := feeds [token ]
50+ adapter := mdl .Repo .GetAdapter (d .Feed )
51+ if adapter .GetName () == ds .QueryPriceFeed && d .FeedType == ds .PythPF && bal .BI .Convert ().Cmp (big .NewInt (10 )) > 0 {
52+ datas , ok := adapter .GetDetails ()["underlyings" ].([]interface {})
53+ if ! ok {
54+ log .Fatal ("Pyth price feed underlyings not found for token:" , token , "adapter:" , adapter .GetAddress ())
55+ }
56+ data , err := pkg .GetPythPrice (datas [0 ].(string ), int64 (ts ))
57+ log .CheckFatal (err )
58+ ans = append (ans , redstone.PytDataWithFeed {
59+ PythData : data ,
60+ Feed : common .HexToAddress (adapter .GetAddress ()),
61+ })
62+ }
63+ }
64+ }
65+ return
66+ }
4067func (mdl * CommonCMAdapter ) retry (oldaccount dc.CreditAccountCallData , blockNum int64 ) (dc.CreditAccountCallData , error ) {
4168 ts := mdl .Repo .SetAndGetBlock (blockNum ).Timestamp
4269 bal := moreThan1Balance (oldaccount .Balances )
4370 bal [mdl .GetUnderlyingToken ()] = core.DBTokenBalance {BI : (* core .BigInt )(big .NewInt (1 ))}
44- redPFs := mdl .priceFeedNeeded (bal )
71+ redPFs := mdl .priceFeedNeededRedStone (bal )
72+ pythPFs := mdl .priceFeedPyth (bal , blockNum )
4573 v3Pods := mdl .Repo .GetRedStonemgr ().GetPodSign (int64 (ts ), redPFs )
46- v3PodsCalls := redstone .GetpodToCalls (300 , common .HexToAddress (mdl .GetCreditFacadeAddr ()), v3Pods , redPFs )
74+ v3PodsCalls := redstone .GetpodToCalls (mdl . Client , core . FetchActualVersion ( mdl . Address , 0 , mdl . Client ), common .HexToAddress (mdl .GetCreditFacadeAddr ()), v3Pods , redPFs , pythPFs )
4775 log .Info ("retrying to get credit account data" , oldaccount .Addr , blockNum , "pods" , len (v3Pods ), "calls" , len (v3PodsCalls ))
4876 //
4977 return mdl .Repo .GetDCWrapper ().Retry (blockNum , oldaccount .Addr , v3Pods , v3PodsCalls )
0 commit comments