Skip to content

Commit

Permalink
Save token symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Sep 30, 2024
1 parent 09f9d89 commit 3ca9166
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/utils/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { defaultConfidenceThreshold } from "./constants";
import { transformTokenDecimals, transformTokens } from "../helpers/tokenMappings";
import { blacklist } from "../data/blacklist";
import { PublicKey } from "@solana/web3.js";
import { sendDiscordText } from "./discord";
import sdk from "@defillama/sdk";

const nullPriceCountThreshold = 10; // insert error when there are more than this many prices missing per hour/day for a bridge

Expand Down Expand Up @@ -405,7 +405,13 @@ export const aggregateData = async (
if (tokensWithNullPrices.size) {
await Promise.all(
Array.from(tokensWithNullPrices).map(async (token: string) => {
await insertOrUpdateTokenWithoutPrice(token);
try {
const [chain, tokenAddress] = token.split(":");
const tokenSymbol = (await sdk.api.erc20.symbol(tokenAddress, chain)).output;
await insertOrUpdateTokenWithoutPrice(token, tokenSymbol);
} catch (e) {
console.error(`Could not insert or update token without price: ${token}`, e);
}
})
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/wrappa/postgres/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ export const closeIdleConnections = async (idleTimeMinutes = 3) => {
}
};

export const insertOrUpdateTokenWithoutPrice = async (token: string) => {
export const insertOrUpdateTokenWithoutPrice = async (token: string, symbol: string) => {
try {
await sql`
INSERT INTO bridges.tokens_without_price (token, occurrence_count)
VALUES (${token}, 1)
INSERT INTO bridges.tokens_without_price (token, occurrence_count, symbol)
VALUES (${token}, 1, ${symbol})
ON CONFLICT (token)
DO UPDATE SET occurrence_count = bridges.tokens_without_price.occurrence_count + 1;
`;
Expand Down

0 comments on commit 3ca9166

Please sign in to comment.