Skip to content

Commit b3feb24

Browse files
committed
fix: remove token price cache, causing inaccurate usd prices
1 parent 083cf06 commit b3feb24

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

indexer/src/services/pair-service.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ import Transaction from '@/models/transaction';
1313

1414
type TokenAmount = number | { decimal: string };
1515

16-
// Cache for token prices in USD
17-
interface TokenPriceCache {
18-
price: number;
19-
timestamp: number;
20-
}
21-
2216
interface CreatePairParams {
2317
moduleName: string;
2418
name: string;
@@ -40,9 +34,6 @@ interface TokenReference {
4034
}
4135

4236
export class PairService {
43-
private static tokenPriceCache: Map<number, TokenPriceCache> = new Map();
44-
private static readonly PRICE_CACHE_TTL = parseInt(process.env.PRICE_CACHE_TTL || '300000', 10); // Default 5 minutes
45-
4637
/**
4738
* Formats a number to exactly 8 decimal places
4839
* @param value The number to format
@@ -186,19 +177,9 @@ export class PairService {
186177
tx?: SequelizeTransaction | undefined,
187178
protocolAddress = DEFAULT_PROTOCOL,
188179
): Promise<number | undefined> {
189-
const now = Date.now();
190-
const cached = this.tokenPriceCache.get(token.id);
191-
192-
// Return cached price if it's still valid
193-
if (cached && now - cached.timestamp < this.PRICE_CACHE_TTL) {
194-
return cached.price;
195-
}
196-
197180
// Calculate new price
198181
const price = await this.calculateTokenPriceInUSD(token, { decimal: '1' }, tx, protocolAddress);
199-
if (price !== undefined) {
200-
this.tokenPriceCache.set(token.id, { price, timestamp: now });
201-
}
182+
202183
return price;
203184
}
204185

0 commit comments

Comments
 (0)