Skip to content

Commit

Permalink
Track tokens without price
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Sep 27, 2024
1 parent 1e6cdee commit 6f96e63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utils/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
insertDailyAggregatedRow,
insertLargeTransactionRow,
insertErrorRow,
insertOrUpdateTokenWithoutPrice,
} from "./wrappa/postgres/write";
import adapters from "../adapters";
import bridgeNetworks from "../data/bridgeNetworkData";
Expand Down Expand Up @@ -286,7 +287,7 @@ export const aggregateData = async (
console.log(errString);
}

let tokensWithNullPrices = new Set();
let tokensWithNullPrices = new Set<string>();
const txsPromises = Promise.all(
txs.map(async (tx) => {
const { id, chain, token, amount, ts, is_deposit, tx_to, tx_from, is_usd_volume, txs_counted_as, origin_chain } =
Expand Down Expand Up @@ -402,8 +403,10 @@ export const aggregateData = async (
);
await txsPromises;
if (tokensWithNullPrices.size) {
await sendDiscordText(
`There are ${tokensWithNullPrices.size} tokens with no price: \n ${Array.from(tokensWithNullPrices).join("\n")}`
await Promise.all(
Array.from(tokensWithNullPrices).map(async (token: string) => {
await insertOrUpdateTokenWithoutPrice(token);
})
);
}
if (tokensWithNullPrices.size > nullPriceCountThreshold) {
Expand Down
13 changes: 13 additions & 0 deletions src/utils/wrappa/postgres/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,16 @@ export const closeIdleConnections = async (idleTimeMinutes = 3) => {
console.error(`Error closing idle connections (Idle time: ${idleTimeMinutes} minutes):`, error);
}
};

export const insertOrUpdateTokenWithoutPrice = async (token: string) => {
try {
await sql`
INSERT INTO bridges.tokens_without_price (token, occurrence_count)
VALUES (${token}, 1)
ON CONFLICT (token)
DO UPDATE SET occurrence_count = bridges.tokens_without_price.occurrence_count + 1;
`;
} catch (e) {
console.error(`Could not insert or update token without price: ${token}`, e);
}
};

0 comments on commit 6f96e63

Please sign in to comment.