This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from humanprotocol/feat/subgraph-daily-updates
feat: add eventDayDatas
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,68 @@ | ||
/* eslint-disable prefer-const */ | ||
import { BigInt, ethereum } from "@graphprotocol/graph-ts"; | ||
import { Launched } from "../../../generated/EscrowFactory/EscrowFactory"; | ||
import { EventDayData } from "../../../generated/schema"; | ||
import { | ||
IntermediateStorage, | ||
Pending, | ||
BulkTransfer, | ||
} from "../../../generated/templates/Escrow/Escrow"; | ||
|
||
const ZERO_BI = BigInt.fromI32(0); | ||
|
||
function getEventDayData(event: ethereum.Event): EventDayData { | ||
let timestamp = event.block.timestamp.toI32(); | ||
let dayID = timestamp / 86400; | ||
let dayStartTimestamp = dayID * 86400; | ||
|
||
let eventDayData = EventDayData.load(dayID.toString()); | ||
if (eventDayData === null) { | ||
eventDayData = new EventDayData(dayID.toString()); | ||
eventDayData.timestamp = dayStartTimestamp; | ||
eventDayData.dailyBulkTransferEvents = ZERO_BI; | ||
eventDayData.dailyIntermediateStorageEvents = ZERO_BI; | ||
eventDayData.dailyPendingEvents = ZERO_BI; | ||
eventDayData.dailyEscrowAmounts = ZERO_BI; | ||
} | ||
return eventDayData; | ||
} | ||
|
||
export function updateIntermediateStorageEventDayData( | ||
event: IntermediateStorage | ||
): EventDayData { | ||
const eventDayData = getEventDayData(event); | ||
//@ts-ignore | ||
eventDayData.dailyIntermediateStorageEvents += BigInt.fromI32(1); | ||
eventDayData.save(); | ||
|
||
return eventDayData; | ||
} | ||
|
||
export function updatePendingEventDayData(event: Pending): EventDayData { | ||
const eventDayData = getEventDayData(event); | ||
//@ts-ignore | ||
eventDayData.dailyPendingEvents += BigInt.fromI32(1); | ||
eventDayData.save(); | ||
|
||
return eventDayData; | ||
} | ||
|
||
export function updateBulkTransferEventDayData( | ||
event: BulkTransfer | ||
): EventDayData { | ||
const eventDayData = getEventDayData(event); | ||
//@ts-ignore | ||
eventDayData.dailyBulkTransferEvents += BigInt.fromI32(1); | ||
eventDayData.save(); | ||
|
||
return eventDayData; | ||
} | ||
|
||
export function updateEscrowAmountDayData(event: Launched): EventDayData { | ||
const eventDayData = getEventDayData(event); | ||
//@ts-ignore | ||
eventDayData.dailyEscrowAmounts += BigInt.fromI32(1); | ||
eventDayData.save(); | ||
|
||
return eventDayData; | ||
} |