Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/worker/job-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { LoopsService } from '../../modules/loops/service';
import { ContentController } from '../../modules/content/content-controller';
import { StakedSonicController } from '../../modules/sts/sts-controller';
import { UserBalancesController } from '../../modules/user/user-balances-controller';
import { ca } from '@bgd-labs/aave-address-book/dist/ChainlinkEthereum-CbJoeh6P';
import { error } from 'console';

const runningJobs: Set<string> = new Set();

Expand Down Expand Up @@ -128,8 +130,17 @@ const setupJobHandlers = async (name: string, chainId: string, res: any, next: N
async () => {
const chains = Object.keys(config) as Chain[];
const service = new PricingService(chains);
const errors: Error[] = [];
for (const chain of chains) {
await service.updatePrices(chain);
try {
await service.updatePrices(chain);
} catch (error) {
console.log(`Error updating prices for chain ${chain}:`, error);
errors.push(error instanceof Error ? error : new Error(`Unknown error: ${error}`));
}
}
if (errors.length > 0) {
throw new Error(errors.map((e) => e.message).join(', '));
}
return 'OK';
},
Expand Down
2 changes: 1 addition & 1 deletion modules/pricing/pricing-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class PricingManager {
// Build initial price map from tokens' currentPrice
const allPrices = new Map<string, { price: number; updatedBy: string }>();
tokens.forEach((token) => {
if (token.currentPrice) {
if (typeof token.currentPrice === 'number' && Number.isFinite(token.currentPrice)) {
allPrices.set(token.address, {
price: token.currentPrice,
updatedBy: token.pricedBy || '',
Expand Down
21 changes: 18 additions & 3 deletions modules/pricing/pricing-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,29 @@ export class PricingRepository {
return [];
}

const validPriceItems = priceItems.filter(
(item) => typeof item.price === 'number' && Number.isFinite(item.price),
);

if (validPriceItems.length === 0) {
return [];
}

// Create latest price map
const latestPrices = Object.fromEntries(tokensForPricing.map((token) => [token.address, token.currentPrice]));
const latestPrices = Object.fromEntries(
tokensForPricing.map((token) => [
token.address,
typeof token.currentPrice === 'number' && Number.isFinite(token.currentPrice)
? token.currentPrice
: undefined,
]),
);

const hourlyTimestamp = timestampRoundedUpToNearestHour();

const operations: any[] = [];

for (const item of priceItems) {
for (const item of validPriceItems) {
// Update or create hourly price in TokenPrice table
operations.push(
prisma.prismaTokenPrice.upsert({
Expand Down Expand Up @@ -170,7 +185,7 @@ export class PricingRepository {

await prismaBulkExecuteOperations(operations);

return priceItems.map((item) => item.address);
return validPriceItems.map((item) => item.address);
}

private collectAllTokenAddresses(tokens: { address: string; underlyingTokenAddress?: string | null }[]): string[] {
Expand Down
Loading