Skip to content

Commit

Permalink
added giveStatus handler for better CM status stats
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-converter committed Dec 18, 2020
1 parent 1bfe1f8 commit 7894fbe
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
5 changes: 4 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type User @entity {
reservationDayCount: BigInt!
referralCount: BigInt!
stakeCount: BigInt!
cmStatus: Boolean!
cmStatusInLaunch: Boolean!
}

type Reservation @entity {
Expand Down Expand Up @@ -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!
Expand Down
5 changes: 3 additions & 2 deletions src/mapping-liquidityTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigInt, ethereum } from "@graphprotocol/graph-ts"
import {
getOrCreateGlobal,
createUser
createUser,
} from "./shared"
import {
ReferralAdded,
Expand Down Expand Up @@ -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()

Expand Down
16 changes: 13 additions & 3 deletions src/mapping-wiseToken.ts
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
10 changes: 8 additions & 2 deletions src/shared.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7894fbe

Please sign in to comment.