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

Fix: Use settings key to sync reward snapshots #297

Merged
merged 1 commit into from
Dec 12, 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
4 changes: 2 additions & 2 deletions packages/seeder/src/events/seedLogsRewardsSubmissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function seedLogsAVSRewardsSubmission(toBlock?: bigint, fromBlock?:
if (log.args.rewardsSubmission?.strategiesAndMultipliers) {
for (const strategyAndMultiplier of log.args.rewardsSubmission.strategiesAndMultipliers) {
strategies.push(strategyAndMultiplier.strategy.toLowerCase())
multipliers.push(String(strategyAndMultiplier.multiplier.toString()))
multipliers.push(strategyAndMultiplier.multiplier.toString())
}

logsAvsRewardsSubmissions.push({
Expand Down Expand Up @@ -103,6 +103,6 @@ export async function seedLogsAVSRewardsSubmission(toBlock?: bigint, fromBlock?:
dbTransactions,
`[Logs] AVS Rewards Submission from: ${fromBlock} to: ${toBlock} size: ${seedLength}`
)
} catch (error) {}
} catch {}
})
}
5 changes: 5 additions & 0 deletions packages/seeder/src/monitors/avsApy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export async function monitorAvsApy() {
try {
// Fetch totalStakers, totalOperators & rewards data for all avs in this iteration
const avsMetrics = await prismaClient.avs.findMany({
where: {
rewardSubmissions: {
some: {}
}
},
include: {
operators: {
where: { isActive: true },
Expand Down
31 changes: 18 additions & 13 deletions packages/seeder/src/seedStakerRewardSnapshots.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import prisma from '@prisma/client'
import { getPrismaClient } from './utils/prismaClient'
import { getNetwork } from './utils/viemClient'
import { bulkUpdateDbTransactions } from './utils/seeder'
import { bulkUpdateDbTransactions, fetchLastSyncTime } from './utils/seeder'
import { fetchTokenPrices } from './utils/tokenPrices'

interface ClaimData {
Expand All @@ -11,12 +11,14 @@ interface ClaimData {
cumulative_amount: string
}

const timeSyncKey = 'lastSyncedTimestamp_stakerRewardSnapshot'

/**
* Seeds the StakerRewardSnapshot table to maintain latest state of all EL stakers
*
* @returns
*/
export async function seedStakerRewardSnapshots() {
export async function seedStakerRewardSnapshots(timestamp?: Date) {
const prismaClient = getPrismaClient()
const bucketUrl = getBucketUrl()
const BATCH_SIZE = 10_000
Expand All @@ -40,18 +42,11 @@ export async function seedStakerRewardSnapshots() {
.split('T')[0]

// Find snapshot date of existing data
const snapshotRecord = await prismaClient.stakerRewardSnapshot.findFirst({
select: {
timestamp: true
},
orderBy: {
timestamp: 'asc' // All snapshots should ideally have the same timestamp, but we check for earliest in case of sync issues
}
})

const snapshotTimestamp = snapshotRecord?.timestamp?.toISOString()?.split('T')[0]
const lastSyncedTimestamp = timestamp
? timestamp?.toISOString()?.split('T')[0]
: (await fetchLastSyncTime(timeSyncKey))?.toISOString()?.split('T')[0]

if (latestSnapshotTimestamp === snapshotTimestamp) {
if (latestSnapshotTimestamp === lastSyncedTimestamp) {
console.log('[In Sync] [Data] Staker Reward Snapshots')
return
}
Expand Down Expand Up @@ -168,6 +163,16 @@ export async function seedStakerRewardSnapshots() {
} finally {
reader.releaseLock()
}

// Update latest time sync key
await prismaClient.settings.upsert({
where: { key: timeSyncKey },
update: { value: Number(latestLog.rewardsCalculationEndTimestamp) * 1000 },
create: {
key: timeSyncKey,
value: Number(latestLog.rewardsCalculationEndTimestamp) * 1000
}
})
} catch {}
}

Expand Down
Loading