From 7894fbed411e80ac13c1543905389ed0d41008c5 Mon Sep 17 00:00:00 2001 From: coffee-converter Date: Fri, 18 Dec 2020 00:04:15 -0600 Subject: [PATCH] added giveStatus handler for better CM status stats --- schema.graphql | 5 ++++- src/mapping-liquidityTransformer.ts | 5 +++-- src/mapping-wiseToken.ts | 16 +++++++++++++--- src/shared.ts | 10 ++++++++-- subgraph.template.yaml | 3 +++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/schema.graphql b/schema.graphql index abbe282..0d1cfe5 100644 --- a/schema.graphql +++ b/schema.graphql @@ -20,6 +20,8 @@ type User @entity { reservationDayCount: BigInt! referralCount: BigInt! stakeCount: BigInt! + cmStatus: Boolean! + cmStatusInLaunch: Boolean! } type Reservation @entity { @@ -78,7 +80,8 @@ type Global @entity { userCount: BigInt! reserverCount: BigInt! referrerCount: BigInt! - cmReferrerCount: BigInt! + cmStatusCount: BigInt! + cmStatusInLaunchCount: BigInt! reservationCount: BigInt! stakeCount: BigInt! stakerCount: BigInt! diff --git a/src/mapping-liquidityTransformer.ts b/src/mapping-liquidityTransformer.ts index 9dafec4..99e79cf 100644 --- a/src/mapping-liquidityTransformer.ts +++ b/src/mapping-liquidityTransformer.ts @@ -1,7 +1,7 @@ import { BigInt, ethereum } from "@graphprotocol/graph-ts" import { getOrCreateGlobal, - createUser + createUser, } from "./shared" import { ReferralAdded, @@ -103,7 +103,8 @@ export function handleReferralAdded(event: ReferralAdded): void { referrer.referralCount = referrer.referralCount.plus(BigInt.fromI32(1)) referrer.save() if (wasBelowCm && referrer.referralActualWei >= CM_REFERRER_THRESHOLD) { - global.cmReferrerCount = global.cmReferrerCount.plus(BigInt.fromI32(1)) + referrer.cmStatusInLaunch = true + global.cmStatusInLaunchCount = global.cmStatusInLaunchCount.plus(BigInt.fromI32(1)) } global.save() diff --git a/src/mapping-wiseToken.ts b/src/mapping-wiseToken.ts index 089ec9c..742f0fe 100644 --- a/src/mapping-wiseToken.ts +++ b/src/mapping-wiseToken.ts @@ -1,16 +1,26 @@ import { BigInt, ethereum } from "@graphprotocol/graph-ts" import { getOrCreateGlobal, - createUser + createUser, } from "./shared" import { - StakeStart + GiveStatusCall, + StakeStart, } from "../generated/WiseToken/WiseToken" import { Stake, - User + User, } from "../generated/schema" +export function handleGiveStatus (call: GiveStatusCall): void { + let referrer = new User(call.inputs._referrer.toHex()) + referrer.cmStatus = true + referrer.save() + + let global = getOrCreateGlobal(); + global.cmStatusCount = global.cmStatusCount.plus(BigInt.fromI32(1)) +} + export function handleStakeStart (event: StakeStart): void { let global = getOrCreateGlobal(); global.stakeCount = global.stakeCount.plus(BigInt.fromI32(1)) diff --git a/src/shared.ts b/src/shared.ts index 6595a80..3ec82e3 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -1,14 +1,18 @@ import {BigInt} from "@graphprotocol/graph-ts/index"; import {Global, User} from "../generated/schema"; +export const ZERO = BigInt.fromI32(0) +export const ONE = BigInt.fromI32(1) + export function getOrCreateGlobal(): Global | null { let global = Global.load("0") if (global == null) { global = new Global("0") - global.userCount = BigInt.fromI32(0) + global.userCount = ZERO global.reserverCount = BigInt.fromI32(0) global.referrerCount = BigInt.fromI32(0) - global.cmReferrerCount = BigInt.fromI32(0) + global.cmStatusCount = BigInt.fromI32(0) + global.cmStatusInLaunchCount = BigInt.fromI32(0) global.reservationCount = BigInt.fromI32(0) global.stakeCount = BigInt.fromI32(0) global.stakerCount = BigInt.fromI32(0) @@ -28,5 +32,7 @@ export function createUser(id: string): User | null { user.reservationDayCount = BigInt.fromI32(0) user.referralCount = BigInt.fromI32(0) user.stakeCount = BigInt.fromI32(0) + user.cmStatus = false + user.cmStatusInLaunch = false return user } \ No newline at end of file diff --git a/subgraph.template.yaml b/subgraph.template.yaml index a237995..7389ed3 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -21,6 +21,9 @@ dataSources: eventHandlers: - event: StakeStart(indexed bytes16,indexed address,indexed address,uint256,uint256,uint256,uint256,uint256,uint256) handler: handleStakeStart + callHandlers: + - function: giveStatus(address) + handler: handleGiveStatus file: ./src/mapping-wiseToken.ts - kind: ethereum/contract name: LiquidityTransformer