Skip to content

Commit

Permalink
rename operatorRewardEvent -> rewardEvent and add op profile
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-aurele-besner committed Aug 8, 2024
1 parent fa53c60 commit 4e1756f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 29 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions indexers/staking-squid/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,24 @@ type Operator @entity {
id: ID! @index
sortId: Int! @index
accountId: String! @index
# creation args
domainId: String! @index
signingKey: String! @index
minimumNominatorStake: BigInt!
nominationTax: Int!
# public profile
name: String! @index
website: String
discord: String
github: String
twitter: String
# chain state
currentTotalStake: BigInt!
currentStorageFeeDeposit: BigInt!
currentEpochRewards: BigInt!
currentTotalShares: BigInt!
rawStatus: String
# increments
totalDeposits: BigInt!
totalTaxCollected: BigInt!
totalRewardsCollected: BigInt!
Expand All @@ -79,10 +89,10 @@ type Operator @entity {
totalConsensusStorageFee: BigInt!
totalDomainExecutionFee: BigInt!
totalBurnedBalance: BigInt!
rawStatus: String
status: OperatorStatus! @index
activeEpochCount: Int!
bundleCount: Int!
# status and timestamps
status: OperatorStatus! @index
lastBundleAt: Int!
createdAt: Int @index
updatedAt: Int @index
Expand Down Expand Up @@ -195,7 +205,7 @@ type OperatorUnlockedFunds @entity {
amount: BigInt!
}

type OperatorRewardEvent @entity {
type RewardEvent @entity {
id: ID! @index
domainId: String! @index
operatorId: String! @index
Expand Down
4 changes: 2 additions & 2 deletions indexers/staking-squid/src/events/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NominatorStatus, OperatorStatus } from "../model";
import type { CtxBlock, CtxEvent, CtxExtrinsic } from "../processor";
import {
createDeposit,
createOperatorRewardEvent,
createRewardEvent,
getOrCreateAccount,
getOrCreateDomain,
getOrCreateNominator,
Expand Down Expand Up @@ -155,7 +155,7 @@ export function processOperatorRewardedEvent(
domain.totalRewardsCollected += amount;
cache.domains.set(domain.id, domain);

const operatorRewardedEvent = createOperatorRewardEvent(block, extrinsic, {
const operatorRewardedEvent = createRewardEvent(block, extrinsic, {
operatorId: operator.id,
domainId: operator.domainId,
amount,
Expand Down
2 changes: 1 addition & 1 deletion indexers/staking-squid/src/model/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export * from "./_depositStatus"
export * from "./withdrawal.model"
export * from "./_withdrawalStatus"
export * from "./operatorUnlockedFunds.model"
export * from "./operatorRewardEvent.model"
export * from "./rewardEvent.model"
export * from "./stats.model"
export * from "./statsPerDomain.model"
export * from "./statsPerOperator.model"
2 changes: 2 additions & 0 deletions indexers/staking-squid/src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export const processor = new SubstrateBatchProcessor()
events.domains.storageFeeDeposited.name,
// bundle
events.domains.bundleStored.name,
// unlock
events.domains.fundsUnlocked.name,
// rewards and slashing
events.domains.operatorRewarded.name,
events.domains.operatorSlashed.name,
Expand Down
15 changes: 10 additions & 5 deletions indexers/staking-squid/src/storage/operator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { randomUUID } from "crypto";
import { Operator, OperatorRewardEvent, OperatorStatus } from "../model";
import { Operator, OperatorStatus, RewardEvent } from "../model";
import type { CtxBlock, CtxExtrinsic } from "../processor";
import { getBlockNumber, getTimestamp, operatorUID } from "../utils";
import { Cache } from "../utils/cache";
Expand All @@ -15,6 +15,11 @@ export const createOperator = (
signingKey: "0x",
minimumNominatorStake: BigInt(0),
nominationTax: 0,
name: "",
website: "",
discord: "",
github: "",
twitter: "",
currentTotalStake: BigInt(0),
currentStorageFeeDeposit: BigInt(0),
currentEpochRewards: BigInt(0),
Expand Down Expand Up @@ -59,12 +64,12 @@ export const getOrCreateOperator = (
return operator;
};

export const createOperatorRewardEvent = (
export const createRewardEvent = (
block: CtxBlock,
extrinsic: CtxExtrinsic,
props: Partial<OperatorRewardEvent>
): OperatorRewardEvent =>
new OperatorRewardEvent({
props: Partial<RewardEvent>
): RewardEvent =>
new RewardEvent({
id: randomUUID(),
...props,
blockNumber: getBlockNumber(block),
Expand Down
8 changes: 5 additions & 3 deletions indexers/staking-squid/src/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Domain,
Nominator,
Operator,
OperatorRewardEvent,
RewardEvent,
Stats,
StatsPerDomain,
StatsPerOperator,
Expand All @@ -28,7 +28,7 @@ export type TemporaryCache = {
withdrawals: Map<string, Withdrawal>;
bundles: Map<string, Bundle>;
bundleAuthors: Map<string, BundleAuthor>;
operatorRewardedEvents: Map<string, OperatorRewardEvent>;
operatorRewardedEvents: Map<string, RewardEvent>;
stats: Map<string, Stats>;
statsPerDomain: Map<string, StatsPerDomain>;
statsPerOperator: Map<string, StatsPerOperator>;
Expand Down Expand Up @@ -97,7 +97,9 @@ export const save = async (ctx: Ctx<Store>, cache: Cache) => {
if (!cache.isModified) return;

await Promise.all(
Object.keys(cache).map((k) => saveEntry(ctx, cache, k as keyof Cache))
Object.keys(cache).map((k) =>
k !== "isModified" ? saveEntry(ctx, cache, k as keyof Cache) : null
)
);

// Clear the cache for entries not needed for reference
Expand Down

0 comments on commit 4e1756f

Please sign in to comment.