Skip to content
Open
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
25 changes: 25 additions & 0 deletions abis/RewardsManagerStitched.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@
"name": "RewardsAssigned",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "indexer",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "allocationID",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "HorizonRewardsAssigned",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down
56 changes: 47 additions & 9 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ type Delegator @entity(immutable: false) {
Delegator stake for a single Indexer
"""
type DelegatedStake @entity(immutable: false) {
"Concatenation of Delegator address and Indexer address"
"Concatenation of Delegator address and Provision ID. For compatibility purposes for Horizon, Legacy entities will have the SubgraphService address hardcoded such that <Indexer-SubgraphService> is the provision address"
id: ID!
"Indexer the stake is delegated to"
indexer: Indexer!
Expand Down Expand Up @@ -1305,6 +1305,8 @@ type DelegatedStake @entity(immutable: false) {
idOnL2: String
"ID of the delegation on L1. Null if it's not transferred"
idOnL1: String
"Whether the delegation is still legacy/hasn't had any Horizon native interactions yet"
isLegacy: Boolean!
}

"""
Expand Down Expand Up @@ -1806,7 +1808,7 @@ Analytics daily snapshots
"""
type IndexerDailyData @entity(immutable: false) {
"<INDEXER ADDRESS>-<DAY NUMBER>"
id: Bytes!
id: ID!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand Down Expand Up @@ -1941,11 +1943,14 @@ type IndexerDailyData @entity(immutable: false) {

"[CURRENT] Latest thawing until timestamp for the indexer"
thawingUntil: BigInt!

"DelegatedStake daily snapshots referencing this Indexer snapshot"
delegatedStakesDailyData: [DelegatedStakeDailyData!]! @derivedFrom(field: "indexerDailyData")
}

type DelegatorDailyData @entity(immutable: false) {
"<DELEGATOR ADDRESS>-<DAY NUMBER>"
id: Bytes!
id: ID!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand Down Expand Up @@ -1982,11 +1987,14 @@ type DelegatorDailyData @entity(immutable: false) {

"[CURRENT] Amount of active DelegatedStake entities this Delegator had at this point in time"
activeStakesCount: Int!

"DelegatedStake daily snapshots referencing this Delegator snapshot"
delegatedStakesDailyData: [DelegatedStakeDailyData!]! @derivedFrom(field: "delegatorDailyData")
}

type DelegatedStakeDailyData @entity(immutable: false) {
"<DELEGATOR ADDRESS>-<INDEXER OR PROVISION ID>-<DAY NUMBER>"
id: Bytes!
id: ID!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand All @@ -2012,6 +2020,21 @@ type DelegatedStakeDailyData @entity(immutable: false) {
"Data service for this delegation, if Horizon delegation"
dataService: DataService

"Delegator daily snapshot for this day, if available"
delegatorDailyData: DelegatorDailyData

"Indexer daily snapshot for this day, if available"
indexerDailyData: IndexerDailyData

"Provision daily snapshot for this day, if available"
provisionDailyData: ProvisionDailyData

"DataService daily snapshot for this day, if available"
dataServiceDailyData: DataServiceDailyData

"Whether the delegation is still legacy/hasn't had any Horizon native interactions yet"
isLegacy: Boolean!

"[CURRENT] Amount of staked tokens for this day and this indexer"
stakedTokens: BigInt!

Expand Down Expand Up @@ -2049,9 +2072,12 @@ type DelegatedStakeDailyData @entity(immutable: false) {
stakedTokensTransferredToL2: BigInt!
}

"""
[DEPRECATED] Auxiliary entity retained for compatibility
"""
type DelegatorDelegatedStakeDailyRelation @entity(immutable: false) {
"[DEPRECATED] Auxiliary entity retained for compatibility."
id: Bytes!
id: ID!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand All @@ -2077,7 +2103,7 @@ type DelegatorDelegatedStakeDailyRelation @entity(immutable: false) {

type SubgraphDeploymentDailyData @entity(immutable: false) {
"<SUBGRAPH DEPLOYMENT ID>-<DAY NUMBER>"
id: Bytes!
id: ID!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand Down Expand Up @@ -2145,7 +2171,7 @@ type SubgraphDeploymentDailyData @entity(immutable: false) {

type GraphNetworkDailyData @entity(immutable: false) {
"<NETWORK ID>-<DAY NUMBER>"
id: Bytes!
id: ID!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand Down Expand Up @@ -2323,7 +2349,7 @@ type GraphNetworkDailyData @entity(immutable: false) {

type ProvisionDailyData @entity(immutable: false) {
"<PROVISION ID>-<DAY NUMBER>"
id: Bytes!
id: ID!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand All @@ -2340,6 +2366,15 @@ type ProvisionDailyData @entity(immutable: false) {
indexer: Indexer!
dataService: DataService!

"Indexer daily snapshot for this day, if available"
indexerDailyData: IndexerDailyData

"DataService daily snapshot for this day, if available"
dataServiceDailyData: DataServiceDailyData

"DelegatedStake daily snapshots referencing this Provision snapshot"
delegatedStakesDailyData: [DelegatedStakeDailyData!]! @derivedFrom(field: "provisionDailyData")

"[CURRENT] Tokens provisioned on this provision"
tokensProvisioned: BigInt!

Expand Down Expand Up @@ -2435,7 +2470,7 @@ type ProvisionDailyData @entity(immutable: false) {

type DataServiceDailyData @entity(immutable: false) {
"<DATA SERVICE ID>-<DAY NUMBER>"
id: Bytes!
id: ID!

"Timestamp for the start of the day that this entity represents. UTC+0"
dayStart: BigInt!
Expand All @@ -2449,6 +2484,9 @@ type DataServiceDailyData @entity(immutable: false) {
"Original entity that the daily data entity tracks"
dataService: DataService!

"Provision daily snapshots referencing this DataService snapshot"
provisionsDailyData: [ProvisionDailyData!]! @derivedFrom(field: "dataServiceDailyData")

"[CURRENT] Total tokens provisioned for this data service"
totalTokensProvisioned: BigInt!

Expand Down
44 changes: 25 additions & 19 deletions src/mappings/helpers/daily-data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigInt, BigDecimal, Bytes, ByteArray } from '@graphprotocol/graph-ts'
import { BigInt, BigDecimal } from '@graphprotocol/graph-ts'
import {
GraphNetwork,
GraphNetworkDailyData,
Expand All @@ -15,13 +15,13 @@ import {
DataService,
DataServiceDailyData,
} from '../../types/schema'
import { joinID } from './helpers'

const SECONDS_PER_DAY = 86400
const LAUNCH_DAY = 18613 // 1608163200 / 86400

const BIGINT_ZERO = BigInt.fromI32(0)
const BIGDECIMAL_ZERO = BigDecimal.fromString('0')
const bytesSeparator = Bytes.fromHexString('0xABCDEF')

function dayStart(timestamp: BigInt): BigInt {
let seconds = timestamp.toI32()
Expand All @@ -36,24 +36,16 @@ function toDayNumber(timestamp: BigInt): i32 {
return timestamp.toI32() / SECONDS_PER_DAY - LAUNCH_DAY
}

function asBytesFromDay(dayNumber: i32): Bytes {
return Bytes.fromI32(dayNumber)
}

function bytesFromString(value: string): Bytes {
return changetype<Bytes>(ByteArray.fromUTF8(value))
}

function compoundId(prefix: string, dayBytes: Bytes): Bytes {
return bytesFromString(prefix).concat(bytesSeparator).concat(dayBytes)
function dailyDataId(prefix: string, dayNumber: i32): string {
return joinID([prefix, dayNumber.toString()])
}

export function getAndUpdateGraphNetworkDailyData(
entity: GraphNetwork,
timestamp: BigInt,
): GraphNetworkDailyData {
let dayNumber = toDayNumber(timestamp)
let id = compoundId(entity.id, asBytesFromDay(dayNumber))
let id = dailyDataId(entity.id, dayNumber)

let dailyData = new GraphNetworkDailyData(id)
dailyData.dayStart = dayStart(timestamp)
Expand Down Expand Up @@ -130,7 +122,7 @@ export function getAndUpdateIndexerDailyData(
timestamp: BigInt,
): IndexerDailyData {
let dayNumber = toDayNumber(timestamp)
let id = compoundId(entity.id, asBytesFromDay(dayNumber))
let id = dailyDataId(entity.id, dayNumber)

let dailyData = new IndexerDailyData(id)
dailyData.dayStart = dayStart(timestamp)
Expand Down Expand Up @@ -192,7 +184,7 @@ export function getAndUpdateDelegatorDailyData(
timestamp: BigInt,
): DelegatorDailyData {
let dayNumber = toDayNumber(timestamp)
let id = compoundId(entity.id, asBytesFromDay(dayNumber))
let id = dailyDataId(entity.id, dayNumber)

let dailyData = new DelegatorDailyData(id)
dailyData.dayStart = dayStart(timestamp)
Expand All @@ -219,7 +211,7 @@ export function getAndUpdateDelegatedStakeDailyData(
timestamp: BigInt,
): DelegatedStakeDailyData {
let dayNumber = toDayNumber(timestamp)
let id = compoundId(entity.id, asBytesFromDay(dayNumber))
let id = dailyDataId(entity.id, dayNumber)

let dailyData = new DelegatedStakeDailyData(id)
dailyData.dayStart = dayStart(timestamp)
Expand All @@ -230,6 +222,17 @@ export function getAndUpdateDelegatedStakeDailyData(
dailyData.indexer = entity.indexer
dailyData.provision = entity.provision
dailyData.dataService = entity.dataService
dailyData.isLegacy = entity.isLegacy

dailyData.delegatorDailyData = dailyDataId(entity.delegator, dayNumber)
dailyData.indexerDailyData = dailyDataId(entity.indexer, dayNumber)
if (entity.provision != null) {
dailyData.provisionDailyData = dailyDataId(entity.provision!, dayNumber)
}

if (entity.dataService != null) {
dailyData.dataServiceDailyData = dailyDataId(entity.dataService!, dayNumber)
}

dailyData.stakedTokens = entity.stakedTokens
dailyData.unstakedTokens = entity.unstakedTokens
Expand All @@ -254,7 +257,7 @@ export function getAndUpdateSubgraphDeploymentDailyData(
timestamp: BigInt,
): SubgraphDeploymentDailyData {
let dayNumber = toDayNumber(timestamp)
let id = compoundId(entity.id, asBytesFromDay(dayNumber))
let id = dailyDataId(entity.id, dayNumber)

let dailyData = new SubgraphDeploymentDailyData(id)
dailyData.dayStart = dayStart(timestamp)
Expand Down Expand Up @@ -291,7 +294,7 @@ export function getAndUpdateProvisionDailyData(
timestamp: BigInt,
): ProvisionDailyData {
let dayNumber = toDayNumber(timestamp)
let id = compoundId(entity.id, asBytesFromDay(dayNumber))
let id = dailyDataId(entity.id, dayNumber)

let dailyData = new ProvisionDailyData(id)
dailyData.dayStart = dayStart(timestamp)
Expand All @@ -301,6 +304,9 @@ export function getAndUpdateProvisionDailyData(
dailyData.indexer = entity.indexer
dailyData.dataService = entity.dataService

dailyData.indexerDailyData = dailyDataId(entity.indexer, dayNumber)
dailyData.dataServiceDailyData = dailyDataId(entity.dataService, dayNumber)

dailyData.tokensProvisioned = entity.tokensProvisioned
dailyData.tokensThawing = entity.tokensThawing
dailyData.tokensAllocated = entity.tokensAllocated
Expand Down Expand Up @@ -343,7 +349,7 @@ export function getAndUpdateDataServiceDailyData(
timestamp: BigInt,
): DataServiceDailyData {
let dayNumber = toDayNumber(timestamp)
let id = compoundId(entity.id, asBytesFromDay(dayNumber))
let id = dailyDataId(entity.id, dayNumber)

let dailyData = new DataServiceDailyData(id)
dailyData.dayStart = dayStart(timestamp)
Expand Down
Loading
Loading