11package domain
22
33import (
4- sdk "github.com/cosmos/cosmos-sdk/types "
4+ "github.com/osmosis-labs/sqs/domain/osmomath "
55 ingesttypes "github.com/osmosis-labs/sqs/ingest/types"
6+
7+ osmoingesttypes "github.com/osmosis-labs/osmosis/v28/ingest/types"
8+
9+ sdk "github.com/cosmos/cosmos-sdk/types"
610)
711
812// CandidateRoutePoolFiltrerCb defines a candidate route pool filter
913// that takes in a pool and returns true if the pool should be skipped.
10- type CandidateRoutePoolFiltrerCb func (* ingesttypes. PoolWrapper ) bool
14+ type CandidateRoutePoolFiltrerCb func (CandidatePoolWrapper ) bool
1115
1216// CandidateRouteSearchOptions represents the options for finding candidate routes.
1317type CandidateRouteSearchOptions struct {
@@ -30,7 +34,7 @@ type CandidateRouteSearchOptions struct {
3034
3135// ShouldSkipPool returns true if the candidate route algorithm should skip
3236// a given pool by matching at least one of the pool filters
33- func (c CandidateRouteSearchOptions ) ShouldSkipPool (pool * ingesttypes. PoolWrapper ) bool {
37+ func (c CandidateRouteSearchOptions ) ShouldSkipPool (pool CandidatePoolWrapper ) bool {
3438 for _ , filter := range c .PoolFiltersAnyOf {
3539 if filter (pool ) {
3640 return true
@@ -47,19 +51,18 @@ type CandidateRoutePoolIDFilterOptionCb struct {
4751}
4852
4953// ShouldSkipPool returns true of the given pool has ID that is present in c.PoolIDsToSkip
50- func (c CandidateRoutePoolIDFilterOptionCb ) ShouldSkipPool (pool * ingesttypes. PoolWrapper ) bool {
51- poolID := pool .GetId ()
54+ func (c CandidateRoutePoolIDFilterOptionCb ) ShouldSkipPool (pool CandidatePoolWrapper ) bool {
55+ poolID := pool .ID
5256 _ , ok := c .PoolIDsToSkip [poolID ]
5357 return ok
5458}
5559
60+ // ShouldSkipOrderbookPool skips orderbook pools
61+ // by returning true if pool.SQSModel.CosmWasmPoolModel is not nil
62+ // and pool.SQSModel.CosmWasmPoolModel.IsOrderbook() returns true.
5663var (
57- // ShouldSkipOrderbookPool skips orderbook pools
58- // by returning true if pool.SQSModel.CosmWasmPoolModel is not nil
59- // and pool.SQSModel.CosmWasmPoolModel.IsOrderbook() returns true.
60- ShouldSkipOrderbookPool CandidateRoutePoolFiltrerCb = func (pool * ingesttypes.PoolWrapper ) bool {
61- cosmWasmPoolModel := pool .SQSModel .CosmWasmPoolModel
62- return cosmWasmPoolModel != nil && cosmWasmPoolModel .IsOrderbook ()
64+ ShouldSkipOrderbookPool CandidateRoutePoolFiltrerCb = func (pool CandidatePoolWrapper ) bool {
65+ return pool .IsOrderbook
6366 }
6467)
6568
@@ -76,12 +79,33 @@ type CandidateRouteSearcher interface {
7679 FindCandidateRoutesInGivenOut (tokenOut sdk.Coin , tokenInDenom string , options CandidateRouteSearchOptions ) (ingesttypes.CandidateRoutes , error )
7780}
7881
79- // CandidateRouteDenomData represents the data for a candidate route for a given denom.
82+ // CandidateRouteDenomData represents data structure that contains pool data
83+ // required for the candidate route algorithm.
84+ type CandidatePoolWrapper struct {
85+ ID uint64
86+ PoolDenoms []string
87+ PoolLiquidityCap uint64 // Note: the value is truncated if it is larger than uint64
88+ Balances sdk.Coins
89+ IsAlloyTransmuter bool
90+ IsOrderbook bool
91+ }
92+
93+ func NewCandidatePoolWrapper (id uint64 , p osmoingesttypes.SQSPool ) CandidatePoolWrapper {
94+ return CandidatePoolWrapper {
95+ ID : id ,
96+ PoolDenoms : p .PoolDenoms ,
97+ PoolLiquidityCap : osmomath .SafeUint64 (p .PoolLiquidityCap ),
98+ Balances : p .Balances ,
99+ IsAlloyTransmuter : p .CosmWasmPoolModel != nil && p .CosmWasmPoolModel .IsAlloyTransmuter (),
100+ IsOrderbook : p .CosmWasmPoolModel != nil && p .CosmWasmPoolModel .IsOrderbook (),
101+ }
102+ }
103+
80104type CandidateRouteDenomData struct {
81105 // SortedPools is the sorted list of pools for the denom.
82- SortedPools []ingesttypes. PoolI
106+ SortedPools []CandidatePoolWrapper
83107 // CanonicalOrderbooks is the map of canonical orderbooks keyed by the pair token.
84108 // For example if this is candidate route denom data for OSMO and there is a canonical orderbook with ID 23
85109 // for ATOM/OSMO, we would have an entry from ATOM to 23 in this map.
86- CanonicalOrderbooks map [string ]ingesttypes. PoolI
110+ CanonicalOrderbooks map [string ]CandidatePoolWrapper
87111}
0 commit comments