-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
207 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package single_asset_feed | ||
|
||
import ( | ||
"encoding/hex" | ||
|
||
"github.com/Gearbox-protocol/sdk-go/artifacts/multicall" | ||
"github.com/Gearbox-protocol/sdk-go/artifacts/redstone" | ||
"github.com/Gearbox-protocol/sdk-go/core" | ||
"github.com/Gearbox-protocol/sdk-go/core/schemas" | ||
"github.com/Gearbox-protocol/sdk-go/log" | ||
"github.com/Gearbox-protocol/third-eye/ds" | ||
"github.com/Gearbox-protocol/third-eye/models/aggregated_block_feed/base_price_feed" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type SingleAssetFeed struct { | ||
*base_price_feed.BasePriceFeed | ||
} | ||
|
||
func NewSingleAsset(token, oracle string, pfType string, discoveredAt int64, client core.ClientI, repo ds.RepositoryI, pfVersion schemas.PFVersion, underlyingFeeds []string) *SingleAssetFeed { | ||
adapter := base_price_feed.NewBasePriceFeed(token, oracle, pfType, discoveredAt, client, repo, pfVersion) | ||
return NewSingleAssetFromAdapter(adapter.SyncAdapter) | ||
} | ||
|
||
func NewSingleAssetFromAdapter(adapter *ds.SyncAdapter) *SingleAssetFeed { | ||
return &SingleAssetFeed{ | ||
BasePriceFeed: base_price_feed.NewBasePriceFeedFromAdapter(adapter), | ||
} | ||
} | ||
|
||
func (mdl *SingleAssetFeed) GetUnderlyings() (ans []string) { | ||
underlyings := mdl.Details["underlyings"] | ||
log.Info("here", underlyings) | ||
if underlyings != nil { | ||
_underlyings, ok := underlyings.([]interface{}) | ||
if ok { | ||
for _, entry := range _underlyings { | ||
ans = append(ans, entry.(string)) | ||
} | ||
} | ||
} | ||
return | ||
} | ||
|
||
func (mdl *SingleAssetFeed) GetCalls(blockNum int64) (calls []multicall.Multicall2Call, isQueryable bool) { | ||
updateABI := core.GetAbi("UpdatePriceFeed") | ||
for _, entry := range mdl.GetUnderlyings() { | ||
log.Info("here2", entry) | ||
contract, err := redstone.NewRedstone(common.HexToAddress(entry), mdl.Client) | ||
log.CheckFatal(err) | ||
var tokenDetails *core.RedStonePF | ||
if _, ok := mdl.DetailsDS.Info[entry]; ok { | ||
tokenDetails = mdl.DetailsDS.Info[entry] | ||
} else if dataIdBytes, err := contract.DataFeedId(nil); err == nil { | ||
dataId := func() string { | ||
var s []byte | ||
for _, b := range dataIdBytes { | ||
if b != 0 { | ||
s = append(s, b) | ||
} else { | ||
break | ||
} | ||
} | ||
return string(s) | ||
|
||
}() | ||
// | ||
signThreshold, err := contract.GetUniqueSignersThreshold(nil) | ||
log.CheckFatal(err) | ||
token, err := contract.Token(nil) | ||
log.CheckFatal(err) | ||
tokenDetails = &core.RedStonePF{ | ||
Type: 15, | ||
DataServiceId: "redstone-primary-prod", | ||
DataId: dataId, | ||
SignersThreshold: int(signThreshold), | ||
UnderlyingToken: token, | ||
} | ||
mdl.DetailsDS.Info[entry] = tokenDetails | ||
} | ||
if tokenDetails != nil { | ||
pod := mdl.Repo.GetRedStonemgr().GetPodSignWithRedstoneToken(int64(mdl.Repo.SetAndGetBlock(blockNum).Timestamp), *tokenDetails) | ||
update, err := updateABI.Pack("updatePrice", pod.CallData) | ||
log.CheckFatal(err) | ||
calls = append(calls, multicall.Multicall2Call{ | ||
Target: common.HexToAddress(entry), | ||
CallData: update, | ||
}) | ||
} | ||
} | ||
b, err := hex.DecodeString("feaf968c") | ||
log.CheckFatal(err) | ||
calls = append(calls, multicall.Multicall2Call{ | ||
Target: common.HexToAddress(mdl.Address), | ||
CallData: b, | ||
}) | ||
return calls, true | ||
} | ||
|
||
// same as query price feed | ||
// func (*YearnPriceFeed) GetCalls(blockNum int64) (calls []multicall.Multicall2Call, isQueryable bool) { | ||
|
||
func (mdl *SingleAssetFeed) ProcessResult(blockNum int64, results []multicall.Multicall2Result, force ...bool) *schemas.PriceFeed { | ||
result := results[len(results)-1] | ||
if !result.Success { | ||
log.Warnf("Can't get latestRounData for YearnModule in AQFWrapper for %s(%s) at %d", | ||
mdl.GetDetailsByKey("pfType"), mdl.GetAddress(), blockNum) | ||
return nil | ||
// | ||
} | ||
isPriceInUSD := mdl.GetVersion().IsPriceInUSD() | ||
return base_price_feed.ParseQueryRoundData(result.ReturnData, isPriceInUSD, mdl.GetAddress(), blockNum) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.