Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Mar 14, 2024
1 parent 48c4883 commit 83f1bce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
10 changes: 4 additions & 6 deletions router/usecase/precompute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/osmosis-labs/sqs/router/usecase"
)

var (
testAmount = osmomath.NewInt(1234567890323344555)
)

func (s *RouterTestSuite) TestGetPrecomputeOrderOfMagnitude() {

tests := map[string]struct {
Expand Down Expand Up @@ -53,19 +57,13 @@ func (s *RouterTestSuite) TestGetPrecomputeOrderOfMagnitude() {

// go test -benchmem -run=^$ -bench ^BenchmarkGetPrecomputeOrderOfMagnitude$ github.com/osmosis-labs/sqs/router/usecase -count=6
func BenchmarkGetPrecomputeOrderOfMagnitude(b *testing.B) {
// Create a test amount. Change this based on what you expect to be typical inputs for your application.
testAmount := osmomath.NewInt(1234567890323344555) // You can adjust this value for different benchmark scenarios.

for i := 0; i < b.N; i++ {
_ = usecase.GetPrecomputeOrderOfMagnitude(testAmount)
}
}

// go test -benchmem -run=^$ -bench ^BenchmarkOrderOfMagnitude$ github.com/osmosis-labs/sqs/router/usecase -count=6 > old
func BenchmarkOrderOfMagnitude(b *testing.B) {
// Create a test amount. Change this based on what you expect to be typical inputs for your application.
testAmount := osmomath.NewInt(1234567890323344555) // You can adjust this value for different benchmark scenarios.

for i := 0; i < b.N; i++ {
_ = osmomath.OrderOfMagnitude(testAmount.ToLegacyDec())
}
Expand Down
15 changes: 13 additions & 2 deletions tokens/usecase/pricing/chain/pricing_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ var (
},
[]string{"base", "quote"},
)

pricesSpotPriceError = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "sqs_pricing_spot_price_error_total",
Help: "Total number of spot price errors in pricing",
},
[]string{"base", "quote"},
)
)

func init() {
Expand Down Expand Up @@ -149,8 +157,11 @@ func (c *chainPricing) GetPrice(ctx context.Context, baseDenom string, quoteDeno

// Get spot price for the pool.
poolSpotPrice, err := c.RUsecase.GetPoolSpotPrice(ctx, pool.GetId(), tempQuoteDenom, tempBaseDenom)
if err != nil {
// TODO: alert
if err != nil || poolSpotPrice.IsNil() || poolSpotPrice.IsZero() {

// Increase price truncation counter
pricesSpotPriceError.WithLabelValues(baseDenom, quoteDenom).Inc()

useAlternativeMethod = true
break
}
Expand Down

0 comments on commit 83f1bce

Please sign in to comment.