Skip to content

Commit 81d3dfd

Browse files
authored
Merge pull request #494 from solidityteam/fix/token-price-cache
fix: remove token price cache, causing inaccurate usd prices
2 parents 5a89c1c + b3feb24 commit 81d3dfd

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
@@ -191,19 +182,9 @@ export class PairService {
191182
tx?: SequelizeTransaction | undefined,
192183
protocolAddress = DEFAULT_PROTOCOL,
193184
): Promise<number | undefined> {
194-
const now = Date.now();
195-
const cached = this.tokenPriceCache.get(token.id);
196-
197-
// Return cached price if it's still valid
198-
if (cached && now - cached.timestamp < this.PRICE_CACHE_TTL) {
199-
return cached.price;
200-
}
201-
202185
// Calculate new price
203186
const price = await this.calculateTokenPriceInUSD(token, { decimal: '1' }, tx, protocolAddress);
204-
if (price !== undefined) {
205-
this.tokenPriceCache.set(token.id, { price, timestamp: now });
206-
}
187+
207188
return price;
208189
}
209190

0 commit comments

Comments
 (0)