Skip to content

Commit

Permalink
globals, stake fields
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-converter committed Jan 6, 2021
1 parent e98eb8b commit c1911da
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 13 deletions.
22 changes: 16 additions & 6 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ type Global @entity {
reservationActualWei: BigInt!
stakeCount: BigInt!
stakerCount: BigInt!
totalShares: BigInt!
totalStaked: BigInt!
sharePrice: BigInt
sharePricePrevious: BigInt
referrerShares: BigInt!
currentWiseDay: BigInt
ownerlessSupply: BigInt!
circulatingSupply: BigInt!
liquidSupply: BigInt!
mintedSupply: BigInt!
ownedSupply: BigInt!
}

type Stake @entity {
Expand All @@ -103,13 +114,12 @@ type Stake @entity {
startDay: BigInt!
lockDays: BigInt!
daiEquivalent: BigInt!
reward: BigInt!
closeDay: BigInt!
penalty: BigInt!
scraped: BigInt!
reward: BigInt
closeDay: BigInt
penalty: BigInt
scrapedYodas: BigInt!
sharesPenalized: BigInt!
referrerSharesPenalized: BigInt!
scrapeCount: BigInt!
scrapedTotalYodas: BigInt!
lastScrapeDay: BigInt!
lastScrapeDay: BigInt
}
34 changes: 29 additions & 5 deletions src/mapping-wiseToken.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BigInt, ethereum } from "@graphprotocol/graph-ts"
import {
getOrCreateGlobal,
createUser,
Expand All @@ -10,6 +9,9 @@ import {
StakeStart,
StakeEnd,
InterestScraped,
NewGlobals,
NewSharePrice,
WiseToken,
} from "../generated/WiseToken/WiseToken"
import {
Stake,
Expand Down Expand Up @@ -77,11 +79,10 @@ export function handleStakeStart (event: StakeStart): void {
stake.reward = null
stake.closeDay = null
stake.penalty = null
stake.scraped = ZERO
stake.scrapedYodas = ZERO
stake.sharesPenalized = ZERO
stake.referrerSharesPenalized = ZERO
stake.scrapeCount = ZERO
stake.scrapedTotalYodas = ZERO
stake.lastScrapeDay = null
stake.save()
}
Expand All @@ -95,12 +96,35 @@ export function handleStakeEnd (event: StakeEnd): void {
}

export function handleInterestScraped (event: InterestScraped): void {
let stake = Stake.load(event.params.stakerAddress.toHexString())
let stake = Stake.load(event.params.stakeID.toHexString())
stake.scrapeCount = stake.scrapeCount.plus(ONE)
stake.lastScrapeDay = event.params.scrapeDay
stake.scrapedTotalYodas = stake.scrapedTotalYodas.plus(event.params.scrapeAmount)
stake.scrapedYodas = stake.scrapedYodas.plus(event.params.scrapeAmount)
stake.currentShares = stake.currentShares.minus(event.params.stakersPenalty)
stake.sharesPenalized = stake.sharesPenalized.plus(event.params.stakersPenalty)
stake.referrerSharesPenalized = stake.referrerSharesPenalized.plus(event.params.referrerPenalty)
stake.save()
}

export function handleNewGlobals (event: NewGlobals): void {
let global = getOrCreateGlobal()
global.totalShares = event.params.totalShares
global.totalStaked = event.params.totalStaked
global.sharePrice = event.params.shareRate
global.referrerShares = event.params.referrerShares
global.currentWiseDay = event.params.currentWiseDay
let contract = WiseToken.bind(event.address)
global.ownerlessSupply = contract.balanceOf(contract.UNISWAP_PAIR())
global.circulatingSupply = contract.totalSupply()
global.liquidSupply = global.circulatingSupply.minus(global.ownerlessSupply)
global.mintedSupply = global.circulatingSupply.plus(global.totalStaked)
global.ownedSupply = global.liquidSupply.plus(global.totalStaked)
global.save()
}

export function handleNewSharePrice (event: NewSharePrice): void {
let global = getOrCreateGlobal()
global.sharePrice = event.params.newSharePrice
global.sharePricePrevious = event.params.oldSharePrice
global.save()
}
15 changes: 13 additions & 2 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@ export function getOrCreateGlobal(): Global | null {
global.cmStatusCount = ZERO
global.cmStatusInLaunchCount = ZERO
global.reservationCount = ZERO
global.stakeCount = ZERO
global.stakerCount = ZERO
global.reservationEffectiveWei = ZERO
global.reservationActualWei = ZERO
global.stakeCount = ZERO
global.stakerCount = ZERO
global.totalShares = ZERO
global.totalStaked = ZERO
global.sharePrice = null
global.sharePricePrevious = null
global.referrerShares = ZERO
global.currentWiseDay = null
global.ownerlessSupply = ZERO
global.circulatingSupply = ZERO
global.liquidSupply = ZERO
global.mintedSupply = ZERO
global.ownedSupply = ZERO
global.save()
}
return global
Expand Down
4 changes: 4 additions & 0 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ dataSources:
handler: handleStakeEnd
- event: InterestScraped(indexed bytes16,indexed address,uint256,uint256,uint256,uint256,uint256)
handler: handleInterestScraped
- event: NewGlobals(uint256,uint256,uint256,uint256,indexed uint256)
handler: handleNewGlobals
- event: NewSharePrice(uint256,uint256,uint64)
handler: handleNewSharePrice
callHandlers:
- function: giveStatus(address)
handler: handleGiveStatus
Expand Down

0 comments on commit c1911da

Please sign in to comment.