Skip to content

Commit

Permalink
BE-636 | lint:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
deividaspetraitis committed Nov 26, 2024
1 parent 50d9aee commit 64fb507
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 68 deletions.
22 changes: 15 additions & 7 deletions packages/server/src/queries/complex/pools/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand Down
58 changes: 31 additions & 27 deletions packages/server/src/queries/complex/pools/providers/sidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof queryPools>>['data'][number];
type SidecarPool = Awaited<ReturnType<typeof queryPools>>["data"][number];

const poolsCache = new LRUCache<string, CacheEntry>(DEFAULT_LRU_OPTIONS);

Expand Down Expand Up @@ -48,35 +52,36 @@ 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(
() =>
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);
Expand All @@ -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,
};
},
});
}
Expand Down
47 changes: 24 additions & 23 deletions packages/server/src/queries/sidecar/pools.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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. */
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand All @@ -188,8 +189,8 @@ export async function queryPools({
return apiClient<SQSGetPoolsResponse>(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;
});
}
2 changes: 1 addition & 1 deletion packages/server/src/utils/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export function createSortSchema<
export const SortSchema = z.object({
keyPath: z.string(),
direction: z.string(),
})
});
20 changes: 10 additions & 10 deletions packages/trpc/src/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) =>
Expand Down

0 comments on commit 64fb507

Please sign in to comment.