Update predictSlot status on trueval submit (#716)

* Update status

* Fix

* Update contracts version

* Use number for predict slot

* Fixes

* Linter

* Fix

* Fix

* tostring

* Fix

* Fix

* Fix
This commit is contained in:
trizin 2023-08-29 15:40:22 +03:00 committed by GitHub
parent 0c846d5bb2
commit 8a28991f2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -726,7 +726,7 @@ type PredictSlot @entity{
"id = {contract address}-{slot}"
id: ID!
predictContract: PredictContract!
slot: BigInt!
slot: Int!
predictions:[PredictPrediction!] @derivedFrom(field: "slot")
trueValues: [PredictTrueVal!] @derivedFrom(field: "slot")
revenue: BigDecimal!
@ -737,6 +737,8 @@ type PredictSlot @entity{
}
type PredictSettingUpdate @entity{
"id = {contract address}-{txId}-{eventIndex}"
id: ID!

View File

@ -24,7 +24,7 @@ import { getUser } from './utils/userUtils'
function getPredictSlot(
predictContractAddress: string,
slot: BigInt
slot: i32
): PredictSlot {
const id = predictContractAddress + '-' + slot.toString()
let newPredictSlot = PredictSlot.load(id)
@ -44,7 +44,7 @@ function getPredictSlot(
export function handlePredictionSubmitted(event: PredictionSubmitted): void {
const predictSlot = getPredictSlot(
event.address.toHexString(),
event.params.slot
event.params.slot.toI32()
)
const user = getUser(event.params.predictoor.toHex())
const id =
@ -142,7 +142,7 @@ export function handleNewSubscription(event: NewSubscription): void {
export function handleTruevalSubmitted(event: TruevalSubmitted): void {
const predictSlot = getPredictSlot(
event.address.toHexString(),
event.params.slot
event.params.slot.toI32()
)
const id = event.address.toHexString() + '-' + event.params.slot.toString()
const newPredictTrueVals = new PredictTrueVal(id) // they share the same id
@ -170,6 +170,13 @@ export function handleTruevalSubmitted(event: TruevalSubmitted): void {
event.params.roundSumStakes.toBigDecimal(),
BigInt.fromI32(decimals).toI32()
)
if (event.params.status == 1) {
predictSlot.status = 'Paying'
}
if (event.params.status == 2) {
predictSlot.status = 'Canceled'
}
predictSlot.save()
}
@ -229,7 +236,10 @@ export function handleRevenueAdded(event: RevenueAdded): void {
const slot = event.params.slot
for (let i = BigInt.zero(); i.lt(numEpochs); i = i.plus(BigInt.fromI32(1))) {
const targetSlot = slot.plus(secondsPerEpoch.times(i))
const predictSlot = getPredictSlot(event.address.toHexString(), targetSlot)
const predictSlot = getPredictSlot(
event.address.toHexString(),
targetSlot.toI32()
)
predictSlot.revenue = predictSlot.revenue.plus(amountPerEpoch)
predictSlot.save()
const revenueId =