Skip to content

Commit

Permalink
BE-636 | Filtering by incentives
Browse files Browse the repository at this point in the history
  • Loading branch information
deividaspetraitis committed Nov 26, 2024
1 parent 64fb507 commit 0f6553d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
22 changes: 2 additions & 20 deletions packages/server/src/queries/complex/pools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -124,33 +126,13 @@ 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,
nextCursor: pools.nextCursor,
};

// 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) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function getPoolsFromSidecar({
poolIds,
notPoolIds,
types,
incentives,
minLiquidityUsd,
withMarketIncentives = true,
pagination,
Expand All @@ -44,6 +45,7 @@ export function getPoolsFromSidecar({
poolIds?: string[];
notPoolIds?: string[];
types?: PoolType[];
incentives?: string[];
minLiquidityUsd?: number;
withMarketIncentives?: boolean;
pagination?: PaginationType;
Expand All @@ -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) : "") +
Expand All @@ -72,6 +75,7 @@ export function getPoolsFromSidecar({
poolIds,
notPoolIds,
types,
incentives,
minLiquidityCap: minLiquidityUsd?.toString(),
withMarketIncentives,
pagination,
Expand All @@ -81,7 +85,6 @@ export function getPoolsFromSidecar({
"sidecarQueryPools"
)();

//console.log("sidecarPools", sidecarPools);
const reserveCoins = sidecarPools.data.map((sidecarPool) => {
try {
return getListedReservesFromSidecarPool(assetLists, sidecarPool);
Expand Down
29 changes: 29 additions & 0 deletions packages/server/src/queries/sidecar/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,31 @@ export const getPoolTypeIntegers = (filters: string[]): number[] => {
.filter((value) => value !== -1); // Exclude invalid mappings
};

type IncentiveType = Record<string, number>;

// 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<number[]>((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,
Expand All @@ -138,6 +159,7 @@ export async function queryPools({
poolIds?: string[];
notPoolIds?: string[];
types?: string[];
incentives?: string[];
minLiquidityCap?: string;
withMarketIncentives?: boolean;
pagination?: PaginationType;
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion packages/trpc/src/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const poolsRouter = createTRPCRouter({
sort: sortInput,
denoms,
types,
incentiveTypes: _incentiveTypes, // TODO:
incentiveTypes,
cursor,
limit,
},
Expand All @@ -110,6 +110,7 @@ export const poolsRouter = createTRPCRouter({
search,
minLiquidityUsd,
types,
incentives: incentiveTypes,
denoms,
pagination: {
cursor,
Expand Down

0 comments on commit 0f6553d

Please sign in to comment.