From 22afbf94890b65376680e54e6443048057ad5a75 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:22:18 +0200 Subject: [PATCH] BE-664 | Add denoms filter for /pools endpoint (#593) (#594) Introduces a denoms filter for /pools endpoint allowing to filter pools by given list of denoms (cherry picked from commit 242467f141ef6a042b35f116b73269ba14596ae6) Co-authored-by: Deividas Petraitis --- Makefile | 4 +- domain/pools.go | 7 ++ pkg/api/v1beta1/pools/http.go | 11 +++ pkg/api/v1beta1/pools/http_test.go | 19 +++++ pkg/api/v1beta1/pools/pools.pb.go | 125 ++++++++++++++++++++-------- pools/usecase/pools_usecase.go | 25 ++++++ pools/usecase/pools_usecase_test.go | 7 ++ proto/sqs/pools/v1beta1/pools.proto | 5 +- 8 files changed, 165 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 5e9bf8196..aadb078e8 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ endif # --- Tooling & Variables ---------------------------------------------------------------- +include ./scripts/makefiles/proto.mk include ./misc/make/tools.Makefile # Install local dependencies @@ -176,9 +177,6 @@ sqs-update-mainnet-state: bench-pricing: go test -bench BenchmarkGetPrices -run BenchmarkGetPrices github.com/osmosis-labs/sqs/tokens/usecase -count=6 -proto-gen: - protoc --go_out=./ --go-grpc_out=./ --proto_path=./sqsdomain/proto ./sqsdomain/proto/ingest.proto - test-prices-mainnet: CI_SQS_PRICING_WORKER_TEST=true go test \ -timeout 300s \ diff --git a/domain/pools.go b/domain/pools.go index dcf16c9cc..c9a0339a1 100644 --- a/domain/pools.go +++ b/domain/pools.go @@ -128,6 +128,13 @@ func WithMarketIncentives(withMarketIncentives bool) PoolsOption { }) } +// WithDenom configures the pools options with the denom filter. +func WithDenom(denom []string) PoolsOption { + return WithNonNilFilter(func(filter *api.GetPoolsRequestFilter) { + filter.Denom = denom + }) +} + // WithPagination configures the pools options with the pagination request. func WithFilter(f *api.GetPoolsRequestFilter) PoolsOption { return func(o *PoolsOptions) { diff --git a/pkg/api/v1beta1/pools/http.go b/pkg/api/v1beta1/pools/http.go index 3b326f064..8e454523c 100644 --- a/pkg/api/v1beta1/pools/http.go +++ b/pkg/api/v1beta1/pools/http.go @@ -3,6 +3,7 @@ package pools import ( "fmt" "strconv" + "strings" "github.com/osmosis-labs/sqs/delivery/http" "github.com/osmosis-labs/sqs/domain/number" @@ -13,6 +14,7 @@ import ( const ( maxSearchQueryLength = 50 + maxDenoms = 8 ) const ( @@ -23,6 +25,7 @@ const ( queryFilterIDNotIn = "filter[id][not_in]" queryFilterType = "filter[type]" queryFilterIncentive = "filter[incentive]" + queryFilterDenom = "filter[denom]" queryFilterMinLiquidityCap = "filter[min_liquidity_cap]" queryFilterWithMarketIncentives = "filter[with_market_incentives]" queryFilterSearch = "filter[search]" @@ -72,6 +75,7 @@ func (r *GetPoolsRequestFilter) IsPresent(c echo.Context) bool { c.QueryParam(queryFilterIDNotIn) != "" || c.QueryParam(queryFilterType) != "" || c.QueryParam(queryFilterIncentive) != "" || + c.QueryParam(queryFilterDenom) != "" || c.QueryParam(queryMinLiquidityCap) != "" || c.QueryParam(queryFilterMinLiquidityCap) != "" || c.QueryParam(queryWithMarketIncentives) != "" || @@ -126,6 +130,13 @@ func (r *GetPoolsRequestFilter) UnmarshalHTTPRequest(c echo.Context) error { return err } + if denoms := c.QueryParam(queryFilterDenom); len(denoms) > 0 { + r.Denom = strings.Split(denoms, ",") + if len(r.Denom) > maxDenoms { + return fmt.Errorf("too many denoms, max: %d", maxDenoms) + } + } + // Deprecated: use filter[min_liquidity_cap] if p := c.QueryParam(queryMinLiquidityCap); p != "" { r.MinLiquidityCap, err = strconv.ParseUint(c.QueryParam(queryMinLiquidityCap), 10, 64) diff --git a/pkg/api/v1beta1/pools/http_test.go b/pkg/api/v1beta1/pools/http_test.go index 5957abd0b..310e6b6ae 100644 --- a/pkg/api/v1beta1/pools/http_test.go +++ b/pkg/api/v1beta1/pools/http_test.go @@ -45,6 +45,11 @@ func TestGetPoolsRequestFilter_IsPresent(t *testing.T) { queryParams: map[string]string{queryFilterIncentive: "2"}, expectedResult: true, }, + { + name: "With filter[denom]", + queryParams: map[string]string{queryFilterDenom: "2"}, + expectedResult: true, + }, { name: "With filter[search]", queryParams: map[string]string{queryFilterSearch: "search"}, @@ -113,6 +118,7 @@ func TestGetPoolsRequestFilter_UnmarshalHTTPRequest(t *testing.T) { queryFilterIDNotIn: "6,7", queryFilterType: "8,9", queryFilterIncentive: "0,1", + queryFilterDenom: "uosmo,atom", queryMinLiquidityCap: "1000", queryFilterMinLiquidityCap: "2000", queryWithMarketIncentives: "true", @@ -124,6 +130,7 @@ func TestGetPoolsRequestFilter_UnmarshalHTTPRequest(t *testing.T) { PoolIdNotIn: []uint64{6, 7}, Type: []uint64{8, 9}, Incentive: []IncentiveType{0, 1}, + Denom: []string{"uosmo", "atom"}, MinLiquidityCap: 2000, WithMarketIncentives: true, Search: "search", @@ -136,6 +143,8 @@ func TestGetPoolsRequestFilter_UnmarshalHTTPRequest(t *testing.T) { queryFilterID: "1,2", queryFilterIDNotIn: "3,4", queryFilterType: "5", + queryFilterIncentive: "1,2", + queryFilterDenom: "btc,eth", queryFilterMinLiquidityCap: "3000", queryFilterWithMarketIncentives: "true", }, @@ -143,6 +152,8 @@ func TestGetPoolsRequestFilter_UnmarshalHTTPRequest(t *testing.T) { PoolId: []uint64{1, 2}, PoolIdNotIn: []uint64{3, 4}, Type: []uint64{5}, + Incentive: []IncentiveType{1, 2}, + Denom: []string{"btc", "eth"}, MinLiquidityCap: 3000, WithMarketIncentives: true, Search: "search", @@ -198,6 +209,13 @@ func TestGetPoolsRequestFilter_UnmarshalHTTPRequest(t *testing.T) { }, expectError: true, }, + { + name: "Invalid Denom ( too long )", + queryParams: map[string]string{ + queryFilterDenom: "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", + }, + expectError: true, + }, { name: "Invalid Search ( too long )", queryParams: map[string]string{ @@ -232,6 +250,7 @@ func TestGetPoolsRequestFilter_UnmarshalHTTPRequest(t *testing.T) { assert.Equal(t, tt.expectedFilter.PoolIdNotIn, filter.PoolIdNotIn) assert.Equal(t, tt.expectedFilter.Type, filter.Type) assert.Equal(t, tt.expectedFilter.Incentive, filter.Incentive) + assert.Equal(t, tt.expectedFilter.Denom, filter.Denom) assert.Equal(t, tt.expectedFilter.MinLiquidityCap, filter.MinLiquidityCap) assert.Equal(t, tt.expectedFilter.WithMarketIncentives, filter.WithMarketIncentives) } diff --git a/pkg/api/v1beta1/pools/pools.pb.go b/pkg/api/v1beta1/pools/pools.pb.go index 20943ca9e..ffa072cb6 100644 --- a/pkg/api/v1beta1/pools/pools.pb.go +++ b/pkg/api/v1beta1/pools/pools.pb.go @@ -71,8 +71,10 @@ type GetPoolsRequestFilter struct { // with_market_incentives indicates whether to include incentives into pools // response. WithMarketIncentives bool `protobuf:"varint,6,opt,name=with_market_incentives,json=withMarketIncentives,proto3" json:"with_market_incentives,omitempty"` + // denom is the list of denominations to filter pools by. + Denom []string `protobuf:"bytes,7,rep,name=denom,proto3" json:"denom,omitempty"` // search is the search string to filter pools by. - Search string `protobuf:"bytes,7,opt,name=search,proto3" json:"search,omitempty"` + Search string `protobuf:"bytes,8,opt,name=search,proto3" json:"search,omitempty"` } func (m *GetPoolsRequestFilter) Reset() { *m = GetPoolsRequestFilter{} } @@ -150,6 +152,13 @@ func (m *GetPoolsRequestFilter) GetWithMarketIncentives() bool { return false } +func (m *GetPoolsRequestFilter) GetDenom() []string { + if m != nil { + return m.Denom + } + return nil +} + func (m *GetPoolsRequestFilter) GetSearch() string { if m != nil { return m.Search @@ -268,38 +277,39 @@ func init() { func init() { proto.RegisterFile("sqs/pools/v1beta1/pools.proto", fileDescriptor_30f2696e6c186971) } var fileDescriptor_30f2696e6c186971 = []byte{ - // 494 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08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, 0x86, - 0xc6, 0xf6, 0x6b, 0x32, 0x12, 0x5c, 0xd2, 0x93, 0xf7, 0xf0, 0xdf, 0x83, 0xce, 0xe3, 0x3a, 0x80, - 0x77, 0x33, 0x38, 0x77, 0x2f, 0x2e, 0x6f, 0x7a, 0x67, 0x8d, 0x02, 0xae, 0x41, 0xc5, 0xf1, 0xae, - 0x1c, 0xaf, 0xe7, 0x35, 0x10, 0xae, 0xc2, 0xde, 0xa9, 0xe3, 0x78, 0xd7, 0x8d, 0x22, 0xde, 0x07, - 0xa3, 0xef, 0xf4, 0xcf, 0x1b, 0xa5, 0xd3, 0x4f, 0x3f, 0x96, 0x26, 0xba, 0x5f, 0x9a, 0xe8, 0xf7, - 0xd2, 0x44, 0xdf, 0x56, 0x66, 0xe1, 0x7e, 0x65, 0x16, 0x7e, 0xad, 0xcc, 0xc2, 0xe7, 0xce, 0x84, - 0xa9, 0xe9, 0x7c, 0xd8, 0x1a, 0x89, 0xb0, 0x2d, 0x64, 0x28, 0x24, 0x93, 0xaf, 0x66, 0xc1, 0x50, - 0xb6, 0xf5, 0xca, 0xdf, 0x4e, 0xda, 0x41, 0xc4, 0x1e, 0x2e, 0xfd, 0xb0, 0xac, 0x17, 0xf4, 0xf5, - 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xdd, 0x1b, 0xcf, 0x81, 0x16, 0x03, 0x00, 0x00, + // 507 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x93, 0x4f, 0x6f, 0xda, 0x30, + 0x18, 0xc6, 0x31, 0x49, 0xf9, 0xf3, 0xa2, 0x51, 0x6a, 0x75, 0x9d, 0x55, 0x6d, 0x51, 0xc4, 0x76, + 0x88, 0x2a, 0x0d, 0x04, 0xdb, 0x79, 0xda, 0xba, 0xb6, 0x13, 0x5a, 0x0b, 0x28, 0x69, 0x2f, 0xbb, + 0x44, 0x01, 0x3c, 0xb0, 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1, + 0x6a, 0x08, 0x97, 0x61, 0xef, 0xb4, 0xd7, 0xf3, 0xae, 0x6b, 0x79, 0x5c, 0x02, 0xb3, 0xdb, 0xeb, + 0x9e, 0xd7, 0x8c, 0xd3, 0xcf, 0x3f, 0x97, 0x16, 0xba, 0x5f, 0x5a, 0xe8, 0xcf, 0xd2, 0x42, 0xdf, + 0x57, 0x56, 0xee, 0x7e, 0x65, 0xe5, 0x7e, 0xaf, 0xac, 0xdc, 0x97, 0xd6, 0x98, 0xa9, 0xc9, 0x7c, + 0xd0, 0x18, 0x8a, 0xb0, 0x29, 0x64, 0x28, 0x24, 0x93, 0xaf, 0xa7, 0xc1, 0x40, 0x36, 0xf5, 0x43, + 0xb8, 0x1d, 0x37, 0x83, 0x88, 0x3d, 0x7c, 0x0a, 0x83, 0x82, 0xfe, 0x6d, 0xdf, 0xfc, 0x0d, 0x00, + 0x00, 0xff, 0xff, 0x49, 0xa6, 0x71, 0x34, 0x2c, 0x03, 0x00, 0x00, } func (m *GetPoolsRequestFilter) Marshal() (dAtA []byte, err error) { @@ -327,7 +337,16 @@ func (m *GetPoolsRequestFilter) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Search) i = encodeVarintPools(dAtA, i, uint64(len(m.Search))) i-- - dAtA[i] = 0x3a + dAtA[i] = 0x42 + } + if len(m.Denom) > 0 { + for iNdEx := len(m.Denom) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Denom[iNdEx]) + copy(dAtA[i:], m.Denom[iNdEx]) + i = encodeVarintPools(dAtA, i, uint64(len(m.Denom[iNdEx]))) + i-- + dAtA[i] = 0x3a + } } if m.WithMarketIncentives { i-- @@ -552,6 +571,12 @@ func (m *GetPoolsRequestFilter) Size() (n int) { if m.WithMarketIncentives { n += 2 } + if len(m.Denom) > 0 { + for _, s := range m.Denom { + l = len(s) + n += 1 + l + sovPools(uint64(l)) + } + } l = len(m.Search) if l > 0 { n += 1 + l + sovPools(uint64(l)) @@ -961,6 +986,38 @@ func (m *GetPoolsRequestFilter) Unmarshal(dAtA []byte) error { } m.WithMarketIncentives = bool(v != 0) case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPools + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPools + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPools + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = append(m.Denom, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 8: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Search", wireType) } diff --git a/pools/usecase/pools_usecase.go b/pools/usecase/pools_usecase.go index 82ebfd132..2c4255fe8 100644 --- a/pools/usecase/pools_usecase.go +++ b/pools/usecase/pools_usecase.go @@ -492,6 +492,31 @@ func (p *poolsUseCase) GetPools(opts ...domain.PoolsOption) ([]sqsdomain.PoolI, applyFilter(options.Filter, transformer) } + // Denom filter filters pools by pool denoms. + // Given list of denoms in the filter, it will return pools that have at least one denom in the list. + // Order of denoms in the filter list is not important. + if f := options.Filter; f != nil && len(f.Denom) > 0 { + transformer.Filter(func(pool sqsdomain.PoolI) bool { + poolDenoms := pool.GetPoolDenoms() + + // Check if any denom in f.Denom exists in poolDenoms + for _, denom := range f.Denom { + denom = strings.ToLower(denom) + for _, poolDenom := range poolDenoms { + token, err := p.tokenMetadataHolder.GetMetadataByChainDenom(poolDenom) + if err != nil { + continue + } + + if denom == strings.ToLower(token.HumanDenom) || denom == strings.ToLower(token.CoinMinimalDenom) { + return true + } + } + } + return false + }) + } + // Set fetch APR and fees data if configured used by some sort opts below transformer.Range(func(key uint64, value sqsdomain.PoolI) bool { p.setPoolAPRAndFeeDataIfConfigured(value, options) diff --git a/pools/usecase/pools_usecase_test.go b/pools/usecase/pools_usecase_test.go index e88bf0d5a..8b7376b8e 100644 --- a/pools/usecase/pools_usecase_test.go +++ b/pools/usecase/pools_usecase_test.go @@ -757,6 +757,13 @@ func (s *PoolsUsecaseTestSuite) TestGetPools() { expectError: false, validateFunc: nil, }, + { + name: "Denom filter ( multi denom )", + options: []domain.PoolsOption{domain.WithDenom([]string{"osmo", "atom"})}, + expectedLen: 1099, + expectError: false, + validateFunc: nil, + }, { name: "Min liquidity cap filter", options: []domain.PoolsOption{domain.WithMinPoolsLiquidityCap(1_000_000)}, diff --git a/proto/sqs/pools/v1beta1/pools.proto b/proto/sqs/pools/v1beta1/pools.proto index 5975bb8b7..5b7a0a4f2 100644 --- a/proto/sqs/pools/v1beta1/pools.proto +++ b/proto/sqs/pools/v1beta1/pools.proto @@ -36,8 +36,11 @@ message GetPoolsRequestFilter { // response. bool with_market_incentives = 6; + // denom is the list of denominations to filter pools by. + repeated string denom = 7; + // search is the search string to filter pools by. - string search = 7; + string search = 8; } // GetPoolsRequest is the request type for the Service.Get RPC method.