diff --git a/app/app.go b/app/app.go index 4945e4c7..f3aeaf02 100644 --- a/app/app.go +++ b/app/app.go @@ -39,6 +39,7 @@ import ( evmListener "github.com/sprintertech/sprinter-signing/chains/evm/listener" evmMessage "github.com/sprintertech/sprinter-signing/chains/evm/message" "github.com/sprintertech/sprinter-signing/metrics" + "github.com/sprintertech/sprinter-signing/price" lifiConfig "github.com/sprintertech/solver-sdk/pkg/config" "github.com/sprintertech/sprinter-signing/chains/lighter" @@ -49,7 +50,6 @@ import ( "github.com/sprintertech/sprinter-signing/config" "github.com/sprintertech/sprinter-signing/jobs" "github.com/sprintertech/sprinter-signing/keyshare" - "github.com/sprintertech/sprinter-signing/price" "github.com/sprintertech/sprinter-signing/protocol/across" "github.com/sprintertech/sprinter-signing/protocol/lifi" lighterAPI "github.com/sprintertech/sprinter-signing/protocol/lighter" @@ -141,9 +141,6 @@ func Run() error { msgChan := make(chan []*message.Message) sigChn := make(chan interface{}) - priceAPI, err := price.NewPythPricer(ctx) - panicOnError(err) - signatureCache := cache.NewSignatureCache(communication, sygmaMetrics) go signatureCache.Watch(ctx, sigChn) @@ -176,9 +173,9 @@ func Run() error { usdPricer := pyth.NewClient(ctx) err = usdPricer.Start(ctx) - panicOnError(err) multiPricer := aggregator.New(usdPricer) resolver := token.NewTokenResolver(solverConfig, multiPricer) + priceAPI := price.NewPricerProxy(multiPricer) var hubPoolContract across.TokenMatcher acrossPools := make(map[uint64]common.Address) diff --git a/price/pyth.go b/price/pyth.go index 28c9608d..5a5070eb 100644 --- a/price/pyth.go +++ b/price/pyth.go @@ -1,31 +1,24 @@ package price import ( - "context" "fmt" "strings" - "github.com/sprintertech/solver-sdk/pkg/tokenpricing/pyth" + "github.com/sprintertech/solver-sdk/pkg/tokenpricing" ) -type PythPricer struct { - client *pyth.PythClient +type PricerProxy struct { + pricer tokenpricing.USDPricer } -func NewPythPricer(ctx context.Context, opts ...pyth.PythClientOption) (*PythPricer, error) { - client := pyth.NewClient(ctx, opts...) - err := client.Start(ctx) - if err != nil { - return nil, err +func NewPricerProxy(pricer tokenpricing.USDPricer) *PricerProxy { + return &PricerProxy{ + pricer: pricer, } - - return &PythPricer{ - client: pyth.NewClient(ctx, opts...), - }, nil } -func (p *PythPricer) TokenPrice(symbol string) (float64, error) { - data, err := p.client.PriceUSD(strings.ToUpper(symbol)) +func (p *PricerProxy) TokenPrice(symbol string) (float64, error) { + data, err := p.pricer.PriceUSD(strings.ToUpper(symbol)) if err != nil { return 0, fmt.Errorf("failed to fetch pyth price for %s: %w", symbol, err) }