Skip to content

Commit a14e892

Browse files
BE-723 | Fix 0 liquidity pools for candidate routes (#643)
Some candidate routes have their capitalization set to 0 because that's how it's defined in the block data. As a result, the router avoids routing through these pools. This PR fixes the issue by assigning a liquidity capitalization value to candidate routes with a value retrieved from the pools use case, which provides the most up-to-date data.
1 parent 8ea8742 commit a14e892

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

app/sidecar_query_server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net"
77
"net/http"
88
"os"
9-
109
"time"
1110

1211
tenderminapi "cosmossdk.io/api/cosmos/base/tendermint/v1beta1"
@@ -168,6 +167,8 @@ func NewSideCarQueryServer(ctx context.Context, appCodec codec.Codec, config dom
168167
return nil, err
169168
}
170169

170+
routerRepository.SetPoolHandler(poolsUseCase)
171+
171172
// Initialize candidate route searcher
172173
candidateRouteSearcher := routerUseCase.NewCandidateRouteFinder(routerRepository, logger)
173174

router/repository/memory_router_repository.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/osmosis-labs/sqs/log"
1414

1515
"github.com/osmosis-labs/osmosis/osmomath"
16+
sqsosmomath "github.com/osmosis-labs/sqs/domain/osmomath"
1617
)
1718

1819
// BaseFeeRepository represents the contract for a repository handling base fee information
@@ -48,6 +49,7 @@ type candidateRoutes map[string]*domain.CandidateRouteDenomData
4849
type routerRepo struct {
4950
takerFeeMap sync.Map
5051
candidateRouteSearchData atomic.Value
52+
poolHandler mvc.PoolHandler
5153
mu sync.Mutex
5254

5355
baseFeeMx sync.RWMutex
@@ -56,7 +58,7 @@ type routerRepo struct {
5658
logger log.Logger
5759
}
5860

59-
func New(logger log.Logger) RouterRepository {
61+
func New(logger log.Logger) *routerRepo {
6062
repository := &routerRepo{
6163
takerFeeMap: sync.Map{},
6264
baseFeeMx: sync.RWMutex{},
@@ -69,6 +71,10 @@ func New(logger log.Logger) RouterRepository {
6971
return repository
7072
}
7173

74+
func (r *routerRepo) SetPoolHandler(poolHandler mvc.PoolHandler) {
75+
r.poolHandler = poolHandler
76+
}
77+
7278
// GetBaseFee implements RouterRepository.
7379
func (r *routerRepo) GetBaseFee() domain.BaseFee {
7480
r.baseFeeMx.RLock()
@@ -177,6 +183,25 @@ func (r *routerRepo) SetCandidateRouteSearchData(data map[string]*domain.Candida
177183

178184
maps.Copy(newData, oldData)
179185

186+
// Some of the pools from the block data may not have a liquidity cap set or it's set to 0.
187+
// Here we manually update the liquidity cap for such candidate routes based on the pool data so
188+
// that we can still route over such pools.
189+
for denom, value := range newData {
190+
for i := range value.SortedPools {
191+
if value.SortedPools[i].PoolLiquidityCap == 0 {
192+
p, _, err := r.poolHandler.GetPools(domain.WithPoolIDFilter([]uint64{value.SortedPools[i].ID}))
193+
if len(p) == 0 || err != nil {
194+
continue // no pool found
195+
}
196+
197+
if p[0].GetLiquidityCap().GT(osmomath.ZeroInt()) {
198+
newData[denom].SortedPools[i].PoolLiquidityCap = sqsosmomath.SafeUint64(p[0].GetLiquidityCap())
199+
}
200+
}
201+
}
202+
}
203+
204+
// Update new data with block data
180205
for denom, value := range data {
181206
newData[denom] = value
182207
}

0 commit comments

Comments
 (0)