Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: avoid duplicate write + cleanup #664

Merged
merged 2 commits into from
Sep 9, 2024
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
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ const CHAINS: Chain[] = [
.default("https://evm-rpc.sei-apis.com")
.parse(process.env.SEI_MAINNET_RPC_URL),
pricesFromTimestamp: Date.UTC(2024, 0, 1, 0, 0, 0),
maxGetLogsRange: 1000,
maxGetLogsRange: 10000,
tokens: [
{
code: "SEI",
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,13 @@ async function catchupAndWatchChain(
// Iterate through each gateway and attempt to fetch data
for (const gateway of config.ipfsGateways) {
const url = `${gateway}/ipfs/${cid}`;
chainLogger.info(`Trying IPFS gateway: ${gateway} for CID: ${cid}`);
// chainLogger.info(`Trying IPFS gateway: ${gateway} for CID: ${cid}`);

const result = await fetchFromGateway(url);
if (result !== undefined) {
chainLogger.info(
`Fetch successful from gateway: ${gateway} for CID: ${cid}`
);
// chainLogger.info(
// `Fetch successful from gateway: ${gateway} for CID: ${cid}`
// );

// Save to IpfsData table
try {
Expand Down
17 changes: 13 additions & 4 deletions src/prices/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,19 @@ export function createPriceProvider(
});
}

await db.applyChange({
type: "InsertManyPrices",
prices: [newPrice],
});
// Check if the price is already in the database
const existingPrice = await db.getTokenPriceByBlockNumber(
chainId,
newPrice.tokenAddress,
blockNumber
);

if (!existingPrice) {
await db.applyChange({
type: "InsertManyPrices",
prices: [newPrice],
});
}

return { ...newPrice, tokenDecimals: token.decimals };
}
Expand Down
Loading