Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify config path #14

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ generate-mocks: mockery
bin/mockery --config mockery.yaml

run:
go run app/*.go
go run app/*.go --config config.json

redis-start:
docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 -v ./redis-cache/:/data redis/redis-stack:7.2.0-v3
Expand Down
25 changes: 17 additions & 8 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,41 @@ package main

import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"

"github.com/osmosis-labs/osmosis/v21/app"
"github.com/osmosis-labs/sqs/chaininfo/client"
sqslog "github.com/osmosis-labs/sqs/log"
"github.com/redis/go-redis/v9"
"github.com/spf13/viper"

"github.com/osmosis-labs/osmosis/v21/app"
)

func init() {
viper.SetConfigFile(`config.json`)
err := viper.ReadInConfig()
if err != nil {
panic(err)
}

if viper.GetBool(`debug`) {
log.Println("Service RUN on DEBUG mode")
}
}

func main() {
configPath := flag.String("config", "config.json", "config file location")

// Parse the command-line arguments
flag.Parse()

fmt.Println("configPath", *configPath)

viper.SetConfigFile(*configPath)
err := viper.ReadInConfig()
if err != nil {
panic(err)
}

dbHost := viper.GetString(`database.host`)
dbPort := viper.GetString(`database.port`)

Expand All @@ -49,7 +58,7 @@ func main() {
})

redisStatus := redisClient.Ping(context.Background())
_, err := redisStatus.Result()
_, err = redisStatus.Result()
if err != nil {
panic(err)
}
Expand Down
50 changes: 0 additions & 50 deletions app/sqs_config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package main

import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"

"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/sqs/domain"
)

Expand Down Expand Up @@ -62,50 +59,3 @@ var DefaultConfig = Config{
RouteCacheExpirySeconds: 600, // 10 minutes
},
}

// NewConfigFromOptions returns a new sidecar query server config from the given options.
func NewConfigFromOptions(opts servertypes.AppOptions) Config {
isEnabled := osmoutils.ParseBool(opts, groupOptName, "is-enabled", false)

if !isEnabled {
return Config{
IsEnabled: false,
}
}

return Config{
IsEnabled: isEnabled,

StorageHost: osmoutils.ParseString(opts, groupOptName, "db-host"),
StoragePort: osmoutils.ParseString(opts, groupOptName, "db-port"),

ServerAddress: osmoutils.ParseString(opts, groupOptName, "server-address"),
ServerTimeoutDurationSecs: osmoutils.ParseInt(opts, groupOptName, "timeout-duration-secs"),

LoggerFilename: osmoutils.ParseString(opts, groupOptName, "logger-filename"),
LoggerIsProduction: osmoutils.ParseBool(opts, groupOptName, "logger-is-production", false),
LoggerLevel: osmoutils.ParseString(opts, groupOptName, "logger-level"),

ChainGRPCGatewayEndpoint: osmoutils.ParseString(opts, groupOptName, "grpc-gateway-endpoint"),

Router: &domain.RouterConfig{
PreferredPoolIDs: osmoutils.ParseUint64Slice(opts, groupOptName, "preferred-pool-ids"),

MaxPoolsPerRoute: osmoutils.ParseInt(opts, groupOptName, "max-pools-per-route"),

MaxRoutes: osmoutils.ParseInt(opts, groupOptName, "max-routes"),

MaxSplitRoutes: osmoutils.ParseInt(opts, groupOptName, "max-split-routes"),

MaxSplitIterations: osmoutils.ParseInt(opts, groupOptName, "max-split-iterations"),

MinOSMOLiquidity: osmoutils.ParseInt(opts, groupOptName, "min-osmo-liquidity"),

RouteUpdateHeightInterval: osmoutils.ParseInt(opts, groupOptName, "route-update-height-interval"),

RouteCacheEnabled: osmoutils.ParseBool(opts, groupOptName, "route-cache-enabled", false),

RouteCacheExpirySeconds: uint64(osmoutils.ParseInt(opts, groupOptName, "route-cache-expiry-seconds")),
},
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/labstack/echo v3.3.10+incompatible
github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231230033922-af0ba43e918a
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231230033922-af0ba43e918a
github.com/osmosis-labs/osmosis/v21 v21.0.1-0.20240101030300-a42faab1a51d
github.com/osmosis-labs/osmosis/v21 v21.0.1-0.20240104204421-6b55d8fda179
github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240104023234-1209f788ec4c
github.com/prometheus/client_golang v1.17.0
github.com/redis/go-redis/v9 v9.3.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,8 @@ github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231230033922-af0ba43e918a h
github.com/osmosis-labs/osmosis/osmoutils v0.0.7-0.20231230033922-af0ba43e918a/go.mod h1:1jwSXz17AKWG4enDVh3jiQR7aao4+vJcYvUsKUbrOKk=
github.com/osmosis-labs/osmosis/v21 v21.0.1-0.20240101030300-a42faab1a51d h1:CiB/5duU/6orVbJYXVZ5SyniIFnJcaIfsj6kpVlh9e4=
github.com/osmosis-labs/osmosis/v21 v21.0.1-0.20240101030300-a42faab1a51d/go.mod h1:YfLsl5rPASbUDwarFihnrG1prIIj6EkhYPnhUkkeQuU=
github.com/osmosis-labs/osmosis/v21 v21.0.1-0.20240104204421-6b55d8fda179 h1:Irpksxunb+CiquH8zW0LP5F9FQGFlsHT2pWLLFhEpn0=
github.com/osmosis-labs/osmosis/v21 v21.0.1-0.20240104204421-6b55d8fda179/go.mod h1:an3fXmLyeDbb7KT8pYh63bhUbDQTfBQ7FL9pamtJ/x8=
github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20231230033922-af0ba43e918a h1:8E5kfBUgznIr2GGMacb8EmT8EEUpijYmber3NSNwQUE=
github.com/osmosis-labs/osmosis/x/epochs v0.0.3-0.20231230033922-af0ba43e918a/go.mod h1:tQTs2/BbDThu5lm7wWo10LcLORpesqUs6lAc4JrPJ2E=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.9-0.20231230033922-af0ba43e918a h1:0uGi0vDzqZlBQlvdcMp6bjy+uCJiJxTFKD3yTIBFoC8=
Expand Down
12 changes: 6 additions & 6 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJ
github.com/btcsuite/btcd/btcec/v2 v2.2.1/go.mod h1:9/CSmJxmuvqzX9Wh2fXMWToLOHhPd11lSPuIupwTkI8=
github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A=
github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE=
github.com/btcsuite/btcd/btcutil v1.1.2/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0=
github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/bufbuild/buf v1.7.0/go.mod h1:Go40fMAF46PnPLC7jJgTQhAI95pmC0+VtxFKVC0qLq0=
github.com/bufbuild/buf v1.9.0/go.mod h1:1Q+rMHiMVcfgScEF/GOldxmu4o9TrQ2sQQh58K6MscE=
Expand Down Expand Up @@ -784,6 +783,7 @@ github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
Expand All @@ -803,13 +803,13 @@ github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
github.com/go-redis/redis v6.15.8+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/go-toolsmith/astcast v1.0.0/go.mod h1:mt2OdQTeAQcY4DQgPSArJjHCcOwlX+Wl/kwN+LbLGQ4=
github.com/go-toolsmith/astcast v1.1.0/go.mod h1:qdcuFWeGGS2xX5bLM/c3U9lewg7+Zu4mr+xPwZIB4ZU=
github.com/go-toolsmith/astcopy v1.0.0/go.mod h1:vrgyG+5Bxrnz4MZWPF+pI4R8h3qKRjjyvV/DSez4WVQ=
Expand Down Expand Up @@ -1071,6 +1071,7 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i
github.com/jdxcode/netrc v0.0.0-20210204082910-926c7f70242a/go.mod h1:Zi/ZFkEqFHTm7qkjyNJjaWH4LQA9LQhGJyF0lTYGpxw=
github.com/jdxcode/netrc v0.0.0-20221124155335-4616370d1a84/go.mod h1:Zi/ZFkEqFHTm7qkjyNJjaWH4LQA9LQhGJyF0lTYGpxw=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/jgautheron/goconst v1.5.1/go.mod h1:aAosetZ5zaeC/2EfMeRswtxUFBpe2Hr7HzkgX4fanO4=
github.com/jhump/gopoet v0.0.0-20190322174617-17282ff210b3/go.mod h1:me9yfT6IJSlOL3FCfrg+L6yzUEZ+5jW6WHt4Sk+UPUI=
Expand Down Expand Up @@ -1152,7 +1153,6 @@ github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgo
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down Expand Up @@ -1223,6 +1223,7 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
Expand Down Expand Up @@ -1297,6 +1298,7 @@ github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae/go.mod h1:E2VnQOmVuvZB6U
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA=
github.com/moby/term v0.0.0-20221205130635-1aeaba878587/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/moricho/tparallel v0.2.1/go.mod h1:fXEIZxG2vdfl0ZF8b42f5a78EhjjD5mX8qUplsoSU4k=
github.com/moricho/tparallel v0.3.0/go.mod h1:leENX2cUv7Sv2qDgdi0D0fCftN8fRC67Bcn8pqzeYNI=
Expand Down Expand Up @@ -1370,7 +1372,6 @@ github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDs
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
github.com/onsi/gomega v1.28.0/go.mod h1:A1H2JE76sI14WIP57LMKj7FVfCHx3g3BcZVjJG8bjX8=
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
Expand Down Expand Up @@ -1735,7 +1736,6 @@ github.com/uber/jaeger-client-go v2.25.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMW
github.com/uber/jaeger-lib v2.2.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/ulikunitz/xz v0.5.7/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ultraware/funlen v0.0.2/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
Expand Down Expand Up @@ -2066,6 +2066,7 @@ golang.org/x/sys v0.0.0-20201117170446-d9b008d0a637/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201202213521-69691e467435/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210313202042-bd2e13477e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -2402,7 +2403,6 @@ mvdan.cc/unparam v0.0.0-20200501210554-b37ab49443f7/go.mod h1:HGC5lll35J70Y5v7vC
mvdan.cc/unparam v0.0.0-20220706161116-678bad134442/go.mod h1:F/Cxw/6mVrNKqrR2YjFf5CaW0Bw4RL8RfbEf4GRggJk=
mvdan.cc/unparam v0.0.0-20221223090309-7455f1af531d/go.mod h1:IeHQjmn6TOD+e4Z3RFiZMMsLVL+A96Nvptar8Fj71is=
mvdan.cc/unparam v0.0.0-20230312165513-e84e2d14e3b8/go.mod h1:Oh/d7dEtzsNHGOq1Cdv8aMm3KdKhVvPbRQcM8WFpBR8=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
pack.ag/amqp v0.11.2/go.mod h1:4/cbmt4EJXSKlG6LCfWHoqmN0uFdy5i/+YFz+fTfhV4=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.15/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
Expand Down
3 changes: 1 addition & 2 deletions middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"time"

"github.com/labstack/echo"
"github.com/osmosis-labs/sqs/domain"
"github.com/prometheus/client_golang/prometheus"

"github.com/osmosis-labs/osmosis/v21/ingest/sqs/domain"
)

// GoMiddleware represent the data-struct for middleware
Expand Down
10 changes: 10 additions & 0 deletions router/usecase/dynamic_splits.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (r *Router) GetSplitQuote(routes []route.RouteImpl, tokenIn sdk.Coin) (doma
return nil, err
}

if bestSplit.amountOut.IsZero() {
return nil, errors.New("amount out is zero, try increasing amount in")
}

totalIncrementsInSplits := uint8(0)
resultRoutes := make([]domain.SplitRoute, 0, len(routes))
totalAmoutOutFromSplits := osmomath.ZeroInt()
Expand Down Expand Up @@ -209,6 +213,12 @@ func getAmountOut(route route.RouteImpl, memoRouteIndex uint8, memo []map[uint8]
return osmomath.Int{}, err
}

if coinOut.Amount.IsNil() || coinOut.Amount.IsZero() {
zeroResult := osmomath.ZeroInt()
memo[memoRouteIndex][currentIncrement] = zeroResult
return zeroResult, nil
}

currentAmtOut = coinOut.Amount

// Memoize
Expand Down
8 changes: 8 additions & 0 deletions router/usecase/optimized_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ func (r *Router) estimateAndRankSingleRouteQuote(routes []route.RouteImpl, token

routesWithAmountOut := make([]RouteWithOutAmount, 0, len(routes))

errors := []error{}

for _, route := range routes {
directRouteTokenOut, err := route.CalculateTokenOutByTokenIn(tokenIn)
if err != nil {
r.logger.Debug("skipping single route due to error in estimate", zap.Error(err))
errors = append(errors, err)
continue
}

Expand All @@ -61,6 +64,11 @@ func (r *Router) estimateAndRankSingleRouteQuote(routes []route.RouteImpl, token
})
}

// If we skipped all routes due to errors, return the first error
if len(routesWithAmountOut) == 0 && len(errors) > 0 {
return nil, nil, errors[0]
}

// Sort by amount out in descending order
sort.Slice(routesWithAmountOut, func(i, j int) bool {
return routesWithAmountOut[i].OutAmount.GT(routesWithAmountOut[j].OutAmount)
Expand Down
5 changes: 5 additions & 0 deletions router/usecase/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func (r *RouteImpl) CalculateTokenOutByTokenIn(tokenIn sdk.Coin) (tokenOut sdk.C
for _, pool := range r.Pools {
// Charge taker fee
tokenIn = pool.ChargeTakerFeeExactIn(tokenIn)
tokenInAmt := tokenIn.Amount.ToLegacyDec()

if tokenInAmt.IsNil() || tokenInAmt.IsZero() {
return sdk.Coin{}, nil
}

tokenOut, err = pool.CalculateTokenOutByTokenIn(tokenIn)
if err != nil {
Expand Down
Loading