From d37ba0fd5feece6fb80d8c9302594401c14ea355 Mon Sep 17 00:00:00 2001 From: Chris Jacobs Date: Tue, 24 Dec 2024 02:51:54 -0800 Subject: [PATCH] fix a bug in otoken daily stats --- scripts/generate-validations.ts | 9 ++++++++- src/templates/otoken/otoken.ts | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/generate-validations.ts b/scripts/generate-validations.ts index e0725316..48b6f120 100644 --- a/scripts/generate-validations.ts +++ b/scripts/generate-validations.ts @@ -12,7 +12,7 @@ const LIMIT = 1000 const gql = (query: string) => query const executeQuery = async (query: string) => { - const response = await fetch('https://origin.squids.live/origin-squid@v65/api/graphql', { + const response = await fetch('https://origin.squids.live/origin-squid@v66/api/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -32,6 +32,10 @@ const takeValidationEntries = (arr: any[]) => { return arr.filter((entry) => entry.blockNumber % 100000 === 0) } +const takeEvery = (arr: any[], n: number = 25) => { + return arr.filter((_, i) => i % n === 0) +} + const oTokens = (prefix: string, address: string) => { return gql(` ${prefix}_oTokens: oTokens( @@ -412,6 +416,9 @@ const main = async () => { } for (const key of Object.keys(result.data)) { entities[key] = takeValidationEntries(result.data[key]) + if (entities[key].length < 5) { + entities[key] = takeEvery(result.data[key], 25) + } } } diff --git a/src/templates/otoken/otoken.ts b/src/templates/otoken/otoken.ts index 2d4a50b5..3bd85ec0 100644 --- a/src/templates/otoken/otoken.ts +++ b/src/templates/otoken/otoken.ts @@ -773,6 +773,9 @@ export const createOTokenProcessor = (params: { const id = `${ctx.chain.id}-${params.otokenAddress}-${dayString}` let entity = result.dailyStats.get(id)?.entity if (entity) { + result.dailyStats.set(entity.id, { block, entity }) + entity.timestamp = new Date(block.header.timestamp) + entity.blockNumber = block.header.height return entity } @@ -859,9 +862,6 @@ export const createOTokenProcessor = (params: { for (const block of ctx.blocks) { await getOTokenDailyStat(block) - } - - for (const block of ctx.blocksWithContent) { for (const trace of block.traces) { if ( trace.type === 'call' &&