add more veOcean stats
This commit is contained in:
parent
81b43ecc20
commit
483cc67d2d
|
@ -338,6 +338,9 @@ type GlobalStatistic @entity {
|
|||
"number of dispensers created"
|
||||
dispenserCount: Int!
|
||||
|
||||
"total ocean locked in veOcean"
|
||||
totalOceanLocked:BigDecimal!
|
||||
|
||||
"current version"
|
||||
version: String
|
||||
}
|
||||
|
@ -504,6 +507,7 @@ type VeDeposit @entity {
|
|||
block: Int!
|
||||
tx: String!
|
||||
veOcean: VeOCEAN!
|
||||
totalOceanLocked:BigDecimal!
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ export function getGlobalStats(): GlobalStatistic {
|
|||
globalStats.datatokenCount = 0
|
||||
globalStats.dispenserCount = 0
|
||||
globalStats.nftCount = 0
|
||||
globalStats.totalOceanLocked = 0
|
||||
globalStats.save()
|
||||
}
|
||||
return globalStats
|
||||
|
@ -33,6 +34,15 @@ export function getOPC(): OPC {
|
|||
return globalStats
|
||||
}
|
||||
|
||||
export function getTotalOceanLocked(): BigDecimal {
|
||||
let globalStats = OPC.load(GLOBAL_ID)
|
||||
if (!globalStats) {
|
||||
globalStats = new OPC(GLOBAL_ID)
|
||||
globalStats.save()
|
||||
}
|
||||
return globalStats.totalOceanLocked
|
||||
}
|
||||
|
||||
export function getTemplates(): Template {
|
||||
let templates = Template.load(GLOBAL_ID)
|
||||
if (!templates) {
|
||||
|
@ -42,6 +52,12 @@ export function getTemplates(): Template {
|
|||
return templates
|
||||
}
|
||||
|
||||
export function updateTotalOceanLocked(amount: BigDecimal): void {
|
||||
const globalStats = getGlobalStats()
|
||||
globalStats.totalOceanLocked = amount
|
||||
globalStats.save()
|
||||
}
|
||||
|
||||
export function addOrder(): void {
|
||||
const globalStats = getGlobalStats()
|
||||
globalStats.orderCount = globalStats.orderCount + 1
|
||||
|
|
|
@ -2,6 +2,10 @@ import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
|
|||
import { Deposit, Supply, Withdraw } from '../@types/veOCEAN/veOCEAN'
|
||||
import { weiToDecimal } from './utils/generic'
|
||||
import { getDeposit, getveOCEAN } from './utils/veUtils'
|
||||
import {
|
||||
getTotalOceanLocked,
|
||||
updateTotalOceanLocked
|
||||
} from './utils/globalUtils'
|
||||
|
||||
export function handleDeposit(event: Deposit): void {
|
||||
const provider = event.params.provider
|
||||
|
@ -9,7 +13,7 @@ export function handleDeposit(event: Deposit): void {
|
|||
const locktime = event.params.locktime
|
||||
const type = event.params.type
|
||||
const ts = event.params.ts
|
||||
|
||||
const totalOceanLocked = getTotalOceanLocked()
|
||||
const veOCEAN = getveOCEAN(provider.toHex())
|
||||
// Create new Deposit entity
|
||||
const deposit = getDeposit(
|
||||
|
@ -28,6 +32,10 @@ export function handleDeposit(event: Deposit): void {
|
|||
deposit.tx = event.transaction.hash.toHex()
|
||||
deposit.sender = event.transaction.from.toHex()
|
||||
deposit.veOcean = veOCEAN.id
|
||||
|
||||
deposit.totalOceanLocked = totalOceanLocked.plus(deposit.value)
|
||||
updateTotalOceanLocked(deposit.totalOceanLocked)
|
||||
|
||||
deposit.save()
|
||||
// --------------------------------------------
|
||||
|
||||
|
@ -39,6 +47,7 @@ export function handleDeposit(event: Deposit): void {
|
|||
}
|
||||
export function handleSupply(event: Supply): void {}
|
||||
export function handleWithdraw(event: Withdraw): void {
|
||||
const totalOceanLocked = getTotalOceanLocked()
|
||||
const provider = event.params.provider
|
||||
const value = event.params.value
|
||||
const ts = event.params.ts
|
||||
|
@ -61,6 +70,8 @@ export function handleWithdraw(event: Withdraw): void {
|
|||
deposit.tx = event.transaction.hash.toHex()
|
||||
deposit.sender = event.transaction.from.toHex()
|
||||
deposit.veOcean = veOCEAN.id
|
||||
deposit.totalOceanLocked = totalOceanLocked.plus(deposit.value) // it's already negated above
|
||||
updateTotalOceanLocked(deposit.totalOceanLocked)
|
||||
deposit.save()
|
||||
// --------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue