Skip to content

Commit c1911da

Browse files
globals, stake fields
1 parent e98eb8b commit c1911da

File tree

4 files changed

+62
-13
lines changed

4 files changed

+62
-13
lines changed

schema.graphql

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ type Global @entity {
9090
reservationActualWei: BigInt!
9191
stakeCount: BigInt!
9292
stakerCount: BigInt!
93+
totalShares: BigInt!
94+
totalStaked: BigInt!
95+
sharePrice: BigInt
96+
sharePricePrevious: BigInt
97+
referrerShares: BigInt!
98+
currentWiseDay: BigInt
99+
ownerlessSupply: BigInt!
100+
circulatingSupply: BigInt!
101+
liquidSupply: BigInt!
102+
mintedSupply: BigInt!
103+
ownedSupply: BigInt!
93104
}
94105

95106
type Stake @entity {
@@ -103,13 +114,12 @@ type Stake @entity {
103114
startDay: BigInt!
104115
lockDays: BigInt!
105116
daiEquivalent: BigInt!
106-
reward: BigInt!
107-
closeDay: BigInt!
108-
penalty: BigInt!
109-
scraped: BigInt!
117+
reward: BigInt
118+
closeDay: BigInt
119+
penalty: BigInt
120+
scrapedYodas: BigInt!
110121
sharesPenalized: BigInt!
111122
referrerSharesPenalized: BigInt!
112123
scrapeCount: BigInt!
113-
scrapedTotalYodas: BigInt!
114-
lastScrapeDay: BigInt!
124+
lastScrapeDay: BigInt
115125
}

src/mapping-wiseToken.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { BigInt, ethereum } from "@graphprotocol/graph-ts"
21
import {
32
getOrCreateGlobal,
43
createUser,
@@ -10,6 +9,9 @@ import {
109
StakeStart,
1110
StakeEnd,
1211
InterestScraped,
12+
NewGlobals,
13+
NewSharePrice,
14+
WiseToken,
1315
} from "../generated/WiseToken/WiseToken"
1416
import {
1517
Stake,
@@ -77,11 +79,10 @@ export function handleStakeStart (event: StakeStart): void {
7779
stake.reward = null
7880
stake.closeDay = null
7981
stake.penalty = null
80-
stake.scraped = ZERO
82+
stake.scrapedYodas = ZERO
8183
stake.sharesPenalized = ZERO
8284
stake.referrerSharesPenalized = ZERO
8385
stake.scrapeCount = ZERO
84-
stake.scrapedTotalYodas = ZERO
8586
stake.lastScrapeDay = null
8687
stake.save()
8788
}
@@ -95,12 +96,35 @@ export function handleStakeEnd (event: StakeEnd): void {
9596
}
9697

9798
export function handleInterestScraped (event: InterestScraped): void {
98-
let stake = Stake.load(event.params.stakerAddress.toHexString())
99+
let stake = Stake.load(event.params.stakeID.toHexString())
99100
stake.scrapeCount = stake.scrapeCount.plus(ONE)
100101
stake.lastScrapeDay = event.params.scrapeDay
101-
stake.scrapedTotalYodas = stake.scrapedTotalYodas.plus(event.params.scrapeAmount)
102+
stake.scrapedYodas = stake.scrapedYodas.plus(event.params.scrapeAmount)
102103
stake.currentShares = stake.currentShares.minus(event.params.stakersPenalty)
103104
stake.sharesPenalized = stake.sharesPenalized.plus(event.params.stakersPenalty)
104105
stake.referrerSharesPenalized = stake.referrerSharesPenalized.plus(event.params.referrerPenalty)
105106
stake.save()
107+
}
108+
109+
export function handleNewGlobals (event: NewGlobals): void {
110+
let global = getOrCreateGlobal()
111+
global.totalShares = event.params.totalShares
112+
global.totalStaked = event.params.totalStaked
113+
global.sharePrice = event.params.shareRate
114+
global.referrerShares = event.params.referrerShares
115+
global.currentWiseDay = event.params.currentWiseDay
116+
let contract = WiseToken.bind(event.address)
117+
global.ownerlessSupply = contract.balanceOf(contract.UNISWAP_PAIR())
118+
global.circulatingSupply = contract.totalSupply()
119+
global.liquidSupply = global.circulatingSupply.minus(global.ownerlessSupply)
120+
global.mintedSupply = global.circulatingSupply.plus(global.totalStaked)
121+
global.ownedSupply = global.liquidSupply.plus(global.totalStaked)
122+
global.save()
123+
}
124+
125+
export function handleNewSharePrice (event: NewSharePrice): void {
126+
let global = getOrCreateGlobal()
127+
global.sharePrice = event.params.newSharePrice
128+
global.sharePricePrevious = event.params.oldSharePrice
129+
global.save()
106130
}

src/shared.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,21 @@ export function getOrCreateGlobal(): Global | null {
1919
global.cmStatusCount = ZERO
2020
global.cmStatusInLaunchCount = ZERO
2121
global.reservationCount = ZERO
22-
global.stakeCount = ZERO
23-
global.stakerCount = ZERO
2422
global.reservationEffectiveWei = ZERO
2523
global.reservationActualWei = ZERO
24+
global.stakeCount = ZERO
25+
global.stakerCount = ZERO
26+
global.totalShares = ZERO
27+
global.totalStaked = ZERO
28+
global.sharePrice = null
29+
global.sharePricePrevious = null
30+
global.referrerShares = ZERO
31+
global.currentWiseDay = null
32+
global.ownerlessSupply = ZERO
33+
global.circulatingSupply = ZERO
34+
global.liquidSupply = ZERO
35+
global.mintedSupply = ZERO
36+
global.ownedSupply = ZERO
2637
global.save()
2738
}
2839
return global

subgraph.template.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ dataSources:
2525
handler: handleStakeEnd
2626
- event: InterestScraped(indexed bytes16,indexed address,uint256,uint256,uint256,uint256,uint256)
2727
handler: handleInterestScraped
28+
- event: NewGlobals(uint256,uint256,uint256,uint256,indexed uint256)
29+
handler: handleNewGlobals
30+
- event: NewSharePrice(uint256,uint256,uint64)
31+
handler: handleNewSharePrice
2832
callHandlers:
2933
- function: giveStatus(address)
3034
handler: handleGiveStatus

0 commit comments

Comments
 (0)