From 64fb507aceedfc767a52601969890ba7cb4395df Mon Sep 17 00:00:00 2001 From: Deividas Petraitis Date: Tue, 26 Nov 2024 11:12:35 +0200 Subject: [PATCH] BE-636 | lint:fix --- .../server/src/queries/complex/pools/index.ts | 22 ++++--- .../complex/pools/providers/sidecar.ts | 58 ++++++++++--------- packages/server/src/queries/sidecar/pools.ts | 47 +++++++-------- packages/server/src/utils/sort.ts | 2 +- packages/trpc/src/pools.ts | 20 +++---- 5 files changed, 81 insertions(+), 68 deletions(-) diff --git a/packages/server/src/queries/complex/pools/index.ts b/packages/server/src/queries/complex/pools/index.ts index 44f0856bdd..afa93f68ad 100644 --- a/packages/server/src/queries/complex/pools/index.ts +++ b/packages/server/src/queries/complex/pools/index.ts @@ -1,11 +1,15 @@ -import { CoinPretty, /*Dec,*/ PricePretty, RatePretty } from "@keplr-wallet/unit"; +import { + CoinPretty, + /*Dec,*/ PricePretty, + RatePretty, +} from "@keplr-wallet/unit"; import { AssetList, Chain } from "@osmosis-labs/types"; import { z } from "zod"; import { IS_TESTNET } from "../../../env"; +import { CursorPaginationSchema } from "../../../utils/pagination"; import { /*search,*/ SearchSchema } from "../../../utils/search"; import { SortSchema } from "../../../utils/sort"; -import { CursorPaginationSchema } from "../../../utils/pagination"; import { PoolRawResponse } from "../../osmosis"; import { PoolIncentives } from "./incentives"; import { getPoolsFromSidecar } from "./providers"; @@ -117,13 +121,17 @@ export async function getPools( total: number; nextCursor: number | undefined; }> { - params.notPoolIds = FILTERABLE_IDS; - let pools = await poolProvider(params); + params.notPoolIds = FILTERABLE_IDS; + const pools = await poolProvider(params); - console.log("getPools pools", pools.data.length); - console.log("getPools pagination", params.pagination); + console.log("getPools pools", pools.data.length); + console.log("getPools pagination", params.pagination); - return { items: pools.data, total: pools.total, nextCursor: pools.nextCursor }; + 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 diff --git a/packages/server/src/queries/complex/pools/providers/sidecar.ts b/packages/server/src/queries/complex/pools/providers/sidecar.ts index 2c9c1280f9..dbd1c3023d 100644 --- a/packages/server/src/queries/complex/pools/providers/sidecar.ts +++ b/packages/server/src/queries/complex/pools/providers/sidecar.ts @@ -5,16 +5,20 @@ import cachified, { CacheEntry } from "cachified"; import { LRUCache } from "lru-cache"; import { EXCLUDED_EXTERNAL_BOOSTS_POOL_IDS, IS_TESTNET } from "../../../../env"; +import { + PaginationType, + PoolProviderResponse, + SortType, +} from "../../../../queries/complex/pools"; import { PoolRawResponse } from "../../../../queries/osmosis"; import { queryPools } from "../../../../queries/sidecar"; -import { PoolProviderResponse, PaginationType, SortType } from "../../../../queries/complex/pools"; import { DEFAULT_LRU_OPTIONS } from "../../../../utils/cache"; import { getAsset } from "../../assets"; import { DEFAULT_VS_CURRENCY } from "../../assets/config"; import { getCosmwasmPoolTypeFromCodeId } from "../env"; import { Pool, PoolIncentiveType, PoolType } from "../index"; -type SidecarPool = Awaited>['data'][number]; +type SidecarPool = Awaited>["data"][number]; const poolsCache = new LRUCache(DEFAULT_LRU_OPTIONS); @@ -48,17 +52,18 @@ export function getPoolsFromSidecar({ if (poolIds && !poolIds.length) { return Promise.resolve({ data: [], total: 0, nextCursor: undefined }); } - + return cachified({ cache: poolsCache, - key: JSON.stringify(assetLists) + - (poolIds ? `sidecar-pools-${poolIds.join(",")}` : "sidecar-pools") + - (notPoolIds?.join(",") ?? "") + - (types?.join(",") ?? "") + - (minLiquidityUsd ?? "") + - withMarketIncentives.toString() + - (pagination ? JSON.stringify(pagination) : "") + - (sort ? JSON.stringify(sort) : ""), + key: + JSON.stringify(assetLists) + + (poolIds ? `sidecar-pools-${poolIds.join(",")}` : "sidecar-pools") + + (notPoolIds?.join(",") ?? "") + + (types?.join(",") ?? "") + + (minLiquidityUsd ?? "") + + withMarketIncentives.toString() + + (pagination ? JSON.stringify(pagination) : "") + + (sort ? JSON.stringify(sort) : ""), ttl: 5_000, // 5 seconds getFreshValue: async () => { const sidecarPools = await timeout( @@ -66,17 +71,17 @@ export function getPoolsFromSidecar({ queryPools({ poolIds, notPoolIds, - types, + types, minLiquidityCap: minLiquidityUsd?.toString(), withMarketIncentives, - pagination, + pagination, sort, }), 9_000, // 9 seconds "sidecarQueryPools" )(); - //console.log("sidecarPools", sidecarPools); + //console.log("sidecarPools", sidecarPools); const reserveCoins = sidecarPools.data.map((sidecarPool) => { try { return getListedReservesFromSidecarPool(assetLists, sidecarPool); @@ -85,19 +90,18 @@ export function getPoolsFromSidecar({ } }); - return { - - data: sidecarPools.data - .map((sidecarPool, index) => - makePoolFromSidecarPool({ - sidecarPool, - reserveCoins: reserveCoins[index] ?? null, - }) - ) - .filter(Boolean) as Pool[], - total: sidecarPools.meta.total_items, - nextCursor: sidecarPools.meta.next_cursor, - } + return { + data: sidecarPools.data + .map((sidecarPool, index) => + makePoolFromSidecarPool({ + sidecarPool, + reserveCoins: reserveCoins[index] ?? null, + }) + ) + .filter(Boolean) as Pool[], + total: sidecarPools.meta.total_items, + nextCursor: sidecarPools.meta.next_cursor, + }; }, }); } diff --git a/packages/server/src/queries/sidecar/pools.ts b/packages/server/src/queries/sidecar/pools.ts index 6ee5579cee..be397a4b02 100644 --- a/packages/server/src/queries/sidecar/pools.ts +++ b/packages/server/src/queries/sidecar/pools.ts @@ -1,7 +1,7 @@ import { apiClient } from "@osmosis-labs/utils"; -import { PaginationType, SortType } from "../../queries/complex/pools"; import { IS_TESTNET, SIDECAR_BASE_URL } from "../../env"; +import { PaginationType, SortType } from "../../queries/complex/pools"; import { ConcentratedPoolRawResponse, CosmwasmPoolRawResponse, @@ -82,14 +82,14 @@ export type SQSPoolFeesData = { }; export type SQSMetaResponse = { - total_items: number; - next_cursor: number | undefined; -} + total_items: number; + next_cursor: number | undefined; +}; export type SQSGetPoolsResponse = { - data: SqsPool[]; - meta: SQSMetaResponse; -} + data: SqsPool[]; + meta: SQSMetaResponse; +}; export type SqsPool = { /** Sidecar returns the same pool models as the node. */ @@ -113,10 +113,10 @@ type PoolType = { // Define the mapping of PoolType enums to integers const PoolTypeEnum: PoolType = { - weighted: 0, // Maps to Balancer - stable: 1, // Maps to Stableswap - concentrated: 2, // Maps to Concentrated - cosmwasm: 3, // Maps to CosmWasm + weighted: 0, // Maps to Balancer + stable: 1, // Maps to Stableswap + concentrated: 2, // Maps to Concentrated + cosmwasm: 3, // Maps to CosmWasm }; // Function to retrieve integer values from the filter types @@ -155,10 +155,10 @@ export async function queryPools({ } if (types) { - params.append("filter[type]", getPoolTypeIntegers(types).join(",")); + params.append("filter[type]", getPoolTypeIntegers(types).join(",")); } - // Note: we do not want to filter the pools if we are in testnet because we do not have accurate pricing + // 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) { params.append("filter[min_liquidity_cap]", minLiquidityCap); @@ -169,16 +169,17 @@ export async function queryPools({ } if (pagination) { - if (pagination.cursor != null) { - params.append("page[cursor]", pagination.cursor.toString()); - } - if (pagination.limit != null) { - params.append("page[size]", pagination.limit.toString()); - } + if (pagination.cursor != null) { + params.append("page[cursor]", pagination.cursor.toString()); + } + if (pagination.limit != null) { + params.append("page[size]", pagination.limit.toString()); + } } if (sort) { - const keyPathWithDirection = sort.direction === "desc" ? `-${sort.keyPath}` : sort.keyPath; + const keyPathWithDirection = + sort.direction === "desc" ? `-${sort.keyPath}` : sort.keyPath; params.append("sort", keyPathWithDirection); } @@ -188,8 +189,8 @@ export async function queryPools({ return apiClient(url.toString()).then((response) => { // When next_cursor is -1 that means we have reached the end of the list if (response.meta.next_cursor === -1) { - response.meta.next_cursor = undefined; + response.meta.next_cursor = undefined; } - return response; - }); + return response; + }); } diff --git a/packages/server/src/utils/sort.ts b/packages/server/src/utils/sort.ts index 347bc08799..709246b3cf 100644 --- a/packages/server/src/utils/sort.ts +++ b/packages/server/src/utils/sort.ts @@ -23,4 +23,4 @@ export function createSortSchema< export const SortSchema = z.object({ keyPath: z.string(), direction: z.string(), -}) +}); diff --git a/packages/trpc/src/pools.ts b/packages/trpc/src/pools.ts index 458b820054..133038323f 100644 --- a/packages/trpc/src/pools.ts +++ b/packages/trpc/src/pools.ts @@ -106,16 +106,16 @@ export const poolsRouter = createTRPCRouter({ ctx, }) => getPools({ - ...ctx, - search, - minLiquidityUsd, - types, - denoms, - pagination: { - cursor, - limit, - }, - sort: sortInput, + ...ctx, + search, + minLiquidityUsd, + types, + denoms, + pagination: { + cursor, + limit, + }, + sort: sortInput, }) ), getSuperfluidPoolIds: publicProcedure.query(({ ctx }) =>