This repository was archived by the owner on Mar 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Properly Index Relayer Stats and Collator Reward Indexing #271
Merged
Merged
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
ad43f89
relayer stats for transaction handling
dharjeezy c401205
indexed collator rewards
dharjeezy 61464d2
implement signature decoding for the relayer field
dharjeezy 0653b7e
use scale-ts
dharjeezy 718871e
remove token list indexing and services
dharjeezy 6a2b9d9
relayer stats migration
dharjeezy ee38e25
remove migration and token List
dharjeezy 801a3a2
remove migration
dharjeezy b8931b4
some improvements
Wizdave97 08ba9d3
add retries for fetch
Wizdave97 f2d2e8f
merge main
Wizdave97 a06e5c9
fix build
Wizdave97 b55ff4b
version some entities
Wizdave97 e2c6833
add migration script
Wizdave97 c6a19fc
nit
Wizdave97 c4fd3be
Merge branch 'main' into dami/index-properly
Wizdave97 7efe801
update migration and test,
dharjeezy c908e8e
migrate command update
dharjeezy f3f356b
make createdAt optional
dharjeezy 5dad735
fix
Wizdave97 bfd8437
index relayer withdraw event
dharjeezy 0bd6b8c
Make cumulative withdrawn optional
Wizdave97 0a5a7c8
Enhance data migration script to order by _block_range DESC for lates…
Wizdave97 4ee48ee
Rename OrderV2 to IOrderV2 in schema.graphql and update related impor…
Wizdave97 7bd6eb0
Update schema.graphql to use IOrderV2 types and adjust intentGatewayV…
Wizdave97 e4d2877
use alternative deduplication
Wizdave97 6931817
fail if any row insertion fails
Wizdave97 d16b5f0
Enhance data migration script to stringify JSON objects for jsonb col…
Wizdave97 71a576a
update intent gateway v2 config
dharjeezy 996aea7
bump sdk
Wizdave97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/indexer/src/handlers/events/collators/collatorRewarded.event.handler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { SubstrateEvent } from "@subql/types" | ||
| import { HyperbridgeCollatorReward, DailyTreasuryCollatorReward } from "@/configs/src/types" | ||
| import { wrap } from "@/utils/event.utils" | ||
| import { Balance } from "@polkadot/types/interfaces" | ||
| import { getBlockTimestamp } from "@/utils/rpc.helpers" | ||
| import { getHostStateMachine } from "@/utils/substrate.helpers" | ||
| import { timestampToDate } from "@/utils/date.helpers" | ||
|
|
||
| /** | ||
| * Handles CollatorRewarded events from pallet-collator-manager | ||
| * Emitted when a collator is rewarded for authoring a block | ||
| */ | ||
| export const handleCollatorRewardedEvent = wrap(async (event: SubstrateEvent): Promise<void> => { | ||
| try { | ||
| const { | ||
| event: { data, method }, | ||
| block, | ||
| } = event | ||
|
|
||
| const [collator, amount] = data | ||
| const collatorAddress = collator.toString() | ||
| const rewardAmount = (amount as unknown as Balance).toBigInt() | ||
|
|
||
| let record = await HyperbridgeCollatorReward.get(collatorAddress) | ||
| if (!record) { | ||
| record = HyperbridgeCollatorReward.create({ | ||
| id: collatorAddress, | ||
| totalRewardAmount: BigInt(0), | ||
| totalBlocksAuthored: BigInt(0), | ||
| }) | ||
| } | ||
|
|
||
| record.totalRewardAmount = (record.totalRewardAmount ?? BigInt(0)) + rewardAmount | ||
| record.totalBlocksAuthored = (record.totalBlocksAuthored ?? BigInt(0)) + BigInt(1) | ||
| record.lastRewardedAt = new Date(block.timestamp!) | ||
|
|
||
| await record.save() | ||
|
|
||
| const hyperbridgeChain = getHostStateMachine(chainId) | ||
| const blockTimestamp = await getBlockTimestamp(block.block.header.hash.toString(), hyperbridgeChain) | ||
| await updateDailyCollatorReward(blockTimestamp, rewardAmount) | ||
|
|
||
| logger.info(`Collator reward indexed: ${collatorAddress} received ${rewardAmount.toString()}`) | ||
| } catch (e) { | ||
| const errorMessage = e instanceof Error ? e.message : String(e) | ||
| logger.error(`Failed to handle collator reward event: ${errorMessage}`) | ||
| } | ||
| }) | ||
|
|
||
| /** | ||
| * Updates the daily collator reward tracking | ||
| */ | ||
| async function updateDailyCollatorReward(timestamp: bigint, amount: bigint): Promise<void> { | ||
| const day = timestampToDate(timestamp) | ||
| day.setUTCHours(0, 0, 0, 0) | ||
| const id = day.toISOString().slice(0, 10) | ||
|
|
||
| let record = await DailyTreasuryCollatorReward.get(id) | ||
|
|
||
| if (!record) { | ||
| record = DailyTreasuryCollatorReward.create({ | ||
| id: id, | ||
| date: day, | ||
| dailyRewardAmount: BigInt(0), | ||
| }) | ||
| } | ||
|
|
||
| record.dailyRewardAmount += amount | ||
| await record.save() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.