Skip to content

Commit

Permalink
add locust and token prices
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Feb 23, 2024
1 parent 9a8067c commit 73a7d2d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion locust/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
- ./:/mnt/locust
# 167.172.160.95:9092 Roman's personal set up
# 174.138.102.174:80 stage set up
command: -f /mnt/locust/locustfile.py --master -H http://167.172.160.95:9092
command: -f /mnt/locust/locustfile.py --master -H http://159.89.14.212:9092

worker:
image: locustio/locust
Expand Down
11 changes: 9 additions & 2 deletions locust/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,12 @@ def routesUOSMOUSDC(self):
def routesUSDCUOSMO(self):
self.client.get(f"/router/routes?tokenIn={USDC}&tokenOutDenom={UOSMO}")

# TODO:
# Add tests for routes search
@task
def tokenPrices(self):
bases = ""
for i in range(len(top10ByVolumePairs)):
bases += top10ByVolumePairs[i]
if i < len(top10ByVolumePairs) - 1:
bases += ","

self.client.get(f"/tokens/prices?base={bases}")
4 changes: 2 additions & 2 deletions router/usecase/optimized_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package usecase

import (
"context"
"errors"
"fmt"
"sort"

"cosmossdk.io/math"
Expand Down Expand Up @@ -39,7 +39,7 @@ func (r *Router) getBestSingleRouteQuote(ctx context.Context, tokenIn sdk.Coin,
// CONTRACT: pools reporitory must be set on the router
func (r *Router) estimateAndRankSingleRouteQuote(ctx context.Context, routes []route.RouteImpl, tokenIn sdk.Coin) (quote domain.Quote, sortedRoutesByAmtOut []RouteWithOutAmount, err error) {
if len(routes) == 0 {
return nil, nil, errors.New("no routes were provided")
return nil, nil, fmt.Errorf("no routes were provided for token in (%s)", tokenIn.Denom)
}

routesWithAmountOut := make([]RouteWithOutAmount, 0, len(routes))
Expand Down
9 changes: 8 additions & 1 deletion tokens/usecase/tokens_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ func (t *tokensUseCase) GetPrices(ctx context.Context, baseDenoms []string, quot

// Given the current base denom, compute all of its prices with the quotes
for _, quoteDenom := range quoteDenoms {
// equal base and quote yield the price of one
if baseDenom == quoteDenom {
byQuoteDenomForGivenBaseResult[quoteDenom] = osmomath.OneBigDec()
continue
}

price, err := pricingSource.GetPrice(ctx, baseDenom, quoteDenom)
if err != nil {
return nil, err
Expand Down Expand Up @@ -227,11 +233,12 @@ func getTokensFromChainRegistry(chainRegistryAssetsFileURL string) (map[string]d
continue
}

token.HumanDenom = denom.Denom
token.Precision = denom.Exponent
}
}

token.HumanDenom = asset.Symbol

tokensByChainDenom[chainDenom] = token
}

Expand Down

0 comments on commit 73a7d2d

Please sign in to comment.