From 0f6553de1d6a2dcef51858dfd8446d588ca99433 Mon Sep 17 00:00:00 2001 From: Deividas Petraitis Date: Tue, 26 Nov 2024 17:08:13 +0200 Subject: [PATCH] BE-636 | Filtering by incentives --- .../server/src/queries/complex/pools/index.ts | 22 ++------------ .../complex/pools/providers/sidecar.ts | 5 +++- packages/server/src/queries/sidecar/pools.ts | 29 +++++++++++++++++++ packages/trpc/src/pools.ts | 3 +- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/packages/server/src/queries/complex/pools/index.ts b/packages/server/src/queries/complex/pools/index.ts index afa93f68ad..2005834506 100644 --- a/packages/server/src/queries/complex/pools/index.ts +++ b/packages/server/src/queries/complex/pools/index.ts @@ -73,6 +73,8 @@ export const PoolFilterSchema = z.object({ minLiquidityUsd: z.number().optional(), /** Only include pools of given type. */ types: z.array(z.enum(allPooltypes)).optional(), + /** Only include pools of provided incentive types */ + incentives: z.array(z.string()).optional(), /** Search using exact match with pools denoms */ denoms: z.array(z.string()).optional(), /** Sort results by keyPath and direction */ @@ -124,9 +126,6 @@ export async function getPools( params.notPoolIds = FILTERABLE_IDS; const pools = await poolProvider(params); - console.log("getPools pools", pools.data.length); - console.log("getPools pagination", params.pagination); - return { items: pools.data, total: pools.total, @@ -134,23 +133,6 @@ export async function getPools( }; // TODO: migrate - //pools = pools.filter((pool) => !FILTERABLE_IDS.includes(pool.id)); // Filter out ids in FILTERABLE_IDS - // if (params?.types) { - // pools = pools.filter(({ type }) => - // params?.types ? params.types.includes(type) : true - // ); - // } - - // // Note: we do not want to filter the pools if we are in testnet because we do not have accurate pricing - // // information. - // if (params?.minLiquidityUsd && !IS_TESTNET) { - // console.log("minLiquidityUsd", params.minLiquidityUsd); - // pools = pools.filter(({ totalFiatValueLocked }) => - // params?.minLiquidityUsd - // ? totalFiatValueLocked.toDec().gte(new Dec(params.minLiquidityUsd)) - // : true - // ); - // } // // add denoms so user can search them // let denomPools = pools.map((pool) => ({ diff --git a/packages/server/src/queries/complex/pools/providers/sidecar.ts b/packages/server/src/queries/complex/pools/providers/sidecar.ts index dbd1c3023d..9e8be59be8 100644 --- a/packages/server/src/queries/complex/pools/providers/sidecar.ts +++ b/packages/server/src/queries/complex/pools/providers/sidecar.ts @@ -34,6 +34,7 @@ export function getPoolsFromSidecar({ poolIds, notPoolIds, types, + incentives, minLiquidityUsd, withMarketIncentives = true, pagination, @@ -44,6 +45,7 @@ export function getPoolsFromSidecar({ poolIds?: string[]; notPoolIds?: string[]; types?: PoolType[]; + incentives?: string[]; minLiquidityUsd?: number; withMarketIncentives?: boolean; pagination?: PaginationType; @@ -60,6 +62,7 @@ export function getPoolsFromSidecar({ (poolIds ? `sidecar-pools-${poolIds.join(",")}` : "sidecar-pools") + (notPoolIds?.join(",") ?? "") + (types?.join(",") ?? "") + + (incentives?.join(",") ?? "") + (minLiquidityUsd ?? "") + withMarketIncentives.toString() + (pagination ? JSON.stringify(pagination) : "") + @@ -72,6 +75,7 @@ export function getPoolsFromSidecar({ poolIds, notPoolIds, types, + incentives, minLiquidityCap: minLiquidityUsd?.toString(), withMarketIncentives, pagination, @@ -81,7 +85,6 @@ export function getPoolsFromSidecar({ "sidecarQueryPools" )(); - //console.log("sidecarPools", sidecarPools); const reserveCoins = sidecarPools.data.map((sidecarPool) => { try { return getListedReservesFromSidecarPool(assetLists, sidecarPool); diff --git a/packages/server/src/queries/sidecar/pools.ts b/packages/server/src/queries/sidecar/pools.ts index be397a4b02..cc2931d930 100644 --- a/packages/server/src/queries/sidecar/pools.ts +++ b/packages/server/src/queries/sidecar/pools.ts @@ -126,10 +126,31 @@ export const getPoolTypeIntegers = (filters: string[]): number[] => { .filter((value) => value !== -1); // Exclude invalid mappings }; +type IncentiveType = Record; + +// Define the mapping of IncentiveType enums to integers +const IncentiveType: IncentiveType = { + superfluid: 0, // Maps to Superfluid + osmosis: 1, // Maps to Osmosis + boost: 2, // Maps to Boost + none: 3, // Maps to None +}; + +// Function to retrieve integer values from the incentive filters +export const getIncentiveTypeIntegers = (filters: string[]): number[] => + filters.reduce((result, filter) => { + const value = IncentiveType[filter]; + if (value !== undefined) { + result.push(value); + } + return result; + }, []); + export async function queryPools({ poolIds, notPoolIds, types, + incentives, minLiquidityCap, withMarketIncentives, pagination, @@ -138,6 +159,7 @@ export async function queryPools({ poolIds?: string[]; notPoolIds?: string[]; types?: string[]; + incentives?: string[]; minLiquidityCap?: string; withMarketIncentives?: boolean; pagination?: PaginationType; @@ -158,6 +180,13 @@ export async function queryPools({ params.append("filter[type]", getPoolTypeIntegers(types).join(",")); } + if (incentives) { + params.append( + "filter[incentive]", + getIncentiveTypeIntegers(incentives).join(",") + ); + } + // Note: we do not want to filter the pools if we are in testnet because we do not have accurate pricing // // information. if (minLiquidityCap && !IS_TESTNET) { diff --git a/packages/trpc/src/pools.ts b/packages/trpc/src/pools.ts index 133038323f..f563f48f42 100644 --- a/packages/trpc/src/pools.ts +++ b/packages/trpc/src/pools.ts @@ -99,7 +99,7 @@ export const poolsRouter = createTRPCRouter({ sort: sortInput, denoms, types, - incentiveTypes: _incentiveTypes, // TODO: + incentiveTypes, cursor, limit, }, @@ -110,6 +110,7 @@ export const poolsRouter = createTRPCRouter({ search, minLiquidityUsd, types, + incentives: incentiveTypes, denoms, pagination: { cursor,