Skip to content

Commit 6f96e63

Browse files
committed
Track tokens without price
1 parent 1e6cdee commit 6f96e63

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/utils/aggregate.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
insertDailyAggregatedRow,
1818
insertLargeTransactionRow,
1919
insertErrorRow,
20+
insertOrUpdateTokenWithoutPrice,
2021
} from "./wrappa/postgres/write";
2122
import adapters from "../adapters";
2223
import bridgeNetworks from "../data/bridgeNetworkData";
@@ -286,7 +287,7 @@ export const aggregateData = async (
286287
console.log(errString);
287288
}
288289

289-
let tokensWithNullPrices = new Set();
290+
let tokensWithNullPrices = new Set<string>();
290291
const txsPromises = Promise.all(
291292
txs.map(async (tx) => {
292293
const { id, chain, token, amount, ts, is_deposit, tx_to, tx_from, is_usd_volume, txs_counted_as, origin_chain } =
@@ -402,8 +403,10 @@ export const aggregateData = async (
402403
);
403404
await txsPromises;
404405
if (tokensWithNullPrices.size) {
405-
await sendDiscordText(
406-
`There are ${tokensWithNullPrices.size} tokens with no price: \n ${Array.from(tokensWithNullPrices).join("\n")}`
406+
await Promise.all(
407+
Array.from(tokensWithNullPrices).map(async (token: string) => {
408+
await insertOrUpdateTokenWithoutPrice(token);
409+
})
407410
);
408411
}
409412
if (tokensWithNullPrices.size > nullPriceCountThreshold) {

src/utils/wrappa/postgres/write.ts

+13
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,16 @@ export const closeIdleConnections = async (idleTimeMinutes = 3) => {
297297
console.error(`Error closing idle connections (Idle time: ${idleTimeMinutes} minutes):`, error);
298298
}
299299
};
300+
301+
export const insertOrUpdateTokenWithoutPrice = async (token: string) => {
302+
try {
303+
await sql`
304+
INSERT INTO bridges.tokens_without_price (token, occurrence_count)
305+
VALUES (${token}, 1)
306+
ON CONFLICT (token)
307+
DO UPDATE SET occurrence_count = bridges.tokens_without_price.occurrence_count + 1;
308+
`;
309+
} catch (e) {
310+
console.error(`Could not insert or update token without price: ${token}`, e);
311+
}
312+
};

0 commit comments

Comments
 (0)