Skip to content

Commit

Permalink
remove pools prices only (#3664)
Browse files Browse the repository at this point in the history
* remove pools prices only

* lint

* remove source denom (#3665)
  • Loading branch information
p0mvn authored Aug 18, 2024
1 parent 54123a4 commit c1e0d39
Showing 4 changed files with 5 additions and 186 deletions.
11 changes: 2 additions & 9 deletions packages/server/src/queries/complex/assets/price/index.ts
Original file line number Diff line number Diff line change
@@ -13,8 +13,6 @@ import { getPriceFromSidecar } from "./providers/sidecar";
/** Provides a price (no caching) given a valid asset from asset list and a fiat currency code.
* @throws if there's an issue getting the price. */
export type PriceProvider = (
assetLists: AssetList[],
chainList: Chain[],
asset: Asset,
currency?: CoingeckoVsCurrencies
) => Promise<Dec>;
@@ -25,7 +23,6 @@ const pricesCache = new LRUCache<string, CacheEntry>(DEFAULT_LRU_OPTIONS);
* @throws If the asset is not found in the asset list registry or the asset's price info is not found (missing in asset list or can't get price). */
export async function getAssetPrice({
assetLists,
chainList,
asset,
currency = "usd",
priceProvider = getPriceFromSidecar,
@@ -34,7 +31,6 @@ export async function getAssetPrice({
assetLists: AssetList[];
asset: { coinDenom?: string } & (
| { coinMinimalDenom: string }
| { sourceDenom: string }
| { chainId: number | string; address: string }
| { coinGeckoId: string }
);
@@ -43,7 +39,6 @@ export async function getAssetPrice({
}): Promise<Dec> {
const coinMinimalDenom =
"coinMinimalDenom" in asset ? asset.coinMinimalDenom : undefined;
const sourceDenom = "sourceDenom" in asset ? asset.sourceDenom : undefined;
const { chainId, address } =
"chainId" in asset && "address" in asset
? asset
@@ -56,7 +51,6 @@ export async function getAssetPrice({
.find(
(asset) =>
(coinMinimalDenom && asset.coinMinimalDenom === coinMinimalDenom) ||
(sourceDenom && asset.sourceDenom === sourceDenom) ||
(chainId &&
address &&
asset.counterparty.some(
@@ -77,16 +71,15 @@ export async function getAssetPrice({
if (!foundAsset)
throw new Error(
`Asset ${
asset.coinDenom ?? coinMinimalDenom ?? sourceDenom
asset.coinDenom ?? coinMinimalDenom
} not found in asset list registry.`
);

return cachified({
key: `asset-price-${foundAsset.coinMinimalDenom}`,
cache: pricesCache,
ttl: 1000 * 10, // 10 seconds
getFreshValue: () =>
priceProvider(assetLists, chainList, foundAsset, currency),
getFreshValue: () => priceProvider(foundAsset, currency),
});
}

157 changes: 0 additions & 157 deletions packages/server/src/queries/complex/assets/price/providers/pools.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dec } from "@keplr-wallet/unit";
import { Asset, AssetList, Chain } from "@osmosis-labs/types";
import { Asset } from "@osmosis-labs/types";
import cachified, { CacheEntry } from "cachified";
import { LRUCache } from "lru-cache";

@@ -9,26 +9,14 @@ import {
} from "../../../../../queries/sidecar/prices";
import { EdgeDataLoader } from "../../../../../utils/batching";
import { LARGE_LRU_OPTIONS } from "../../../../../utils/cache";
import { captureError } from "../../../../../utils/error";
import { getPriceFromPools } from "./pools";

const sidecarCache = new LRUCache<string, CacheEntry>(LARGE_LRU_OPTIONS);

/** Gets price from SQS query server. Currently only supports prices in USDC with decimals. Falls back to pools then querying CoinGecko if not available.
* @throws if there's an issue getting the price. */
export function getPriceFromSidecar(
assetLists: AssetList[],
chainList: Chain[],
asset: Asset
) {
export function getPriceFromSidecar(asset: Asset) {
return getBatchLoader().then((loader) =>
loader
.load(asset.coinMinimalDenom)
.then((price) => new Dec(price))
.catch((e) => {
captureError(e);
return getPriceFromPools(assetLists, chainList, asset);
})
loader.load(asset.coinMinimalDenom).then((price) => new Dec(price))
);
}

5 changes: 0 additions & 5 deletions packages/web/server/api/routers/bridge-transfer.ts
Original file line number Diff line number Diff line change
@@ -145,7 +145,6 @@ export const bridgeTransferRouter = createTRPCRouter({
...ctx,
asset: {
coinMinimalDenom: input.toAsset.address,
sourceDenom: input.toAsset.address,
chainId: input.toChain.chainId,
address: input.toAsset.address,
coinGeckoId: input.toAsset.coinGeckoId,
@@ -169,7 +168,6 @@ export const bridgeTransferRouter = createTRPCRouter({
...ctx,
asset: {
coinMinimalDenom: input.fromAsset.address,
sourceDenom: input.fromAsset.address,
chainId: input.fromChain.chainId,
address: input.fromAsset.address,
coinGeckoId: input.fromAsset.coinGeckoId,
@@ -180,7 +178,6 @@ export const bridgeTransferRouter = createTRPCRouter({
...ctx,
asset: {
coinMinimalDenom: feeCoin.address,
sourceDenom: feeCoin.address,
chainId: quote.transferFee.chainId,
address: quote.transferFee.address,
coinGeckoId: quote.transferFee.coinGeckoId,
@@ -194,7 +191,6 @@ export const bridgeTransferRouter = createTRPCRouter({
{
bridge: input.bridge,
coinMinimalDenom: feeCoin.address,
sourceDenom: feeCoin.address,
chainId: quote.transferFee.chainId,
address: quote.transferFee.address,
coinGeckoId: quote.transferFee.coinGeckoId,
@@ -208,7 +204,6 @@ export const bridgeTransferRouter = createTRPCRouter({
...ctx,
asset: {
coinMinimalDenom: quote.estimatedGasFee.address,
sourceDenom: quote.estimatedGasFee.address,
chainId: quote.fromChain.chainId,
address: quote.estimatedGasFee.address,
coinGeckoId: quote.estimatedGasFee.coinGeckoId,

0 comments on commit c1e0d39

Please sign in to comment.