Skip to content

Commit

Permalink
feat: basic implementation for ThawRequests
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmardefago committed Feb 13, 2025
1 parent d020532 commit 6ce272c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
35 changes: 26 additions & 9 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -847,28 +847,45 @@ type Provision @entity {

tokensProvisioned: BigInt!

"Timestamp when the provision was created"
createdAt: BigInt!

"Service provider tokens that are being thawed (and will stop being slashable soon)"
tokensThawing: BigInt!

"Shares representing the thawing tokens"
sharesThawing: BigInt!

"Max amount that can be taken by the verifier when slashing, expressed in parts-per-million of the amount slashed"
maxVerifierCut: Int!

"Time, in seconds, tokens must thaw before being withdrawn"
thawingPeriod: BigInt!

"Timestamp when the provision was created"
createdAt: BigInt!

"Pending value for maxVerifierCut. Verifier needs to accept it before it becomes active"
maxVerifierCutPending: Int!

"Time, in seconds, tokens must thaw before being withdrawn"
thawingPeriod: BigInt!

"Pending value for thawingPeriod. Verifier needs to accept it before it becomes active"
thawingPeriodPending: BigInt!
}

type ThawRequest @entity {
id: ID!

indexer: Indexer!

service: DataService!

owner: GraphAccount!

"Shares representing the thawing tokens"
shares: BigInt!

"Tokens thawed"
tokens: BigInt!

thawingUntil: BigInt!

valid: Boolean
}

"""
A state channel Allocation representing a single Indexer-SubgraphDeployment stake
"""
Expand Down
32 changes: 19 additions & 13 deletions src/mappings/horizonStaking.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BigInt, log } from '@graphprotocol/graph-ts'
import { addresses } from '../../config/addresses'
import { HorizonStakeDeposited, HorizonStakeLocked, HorizonStakeWithdrawn, TokensDeprovisioned } from '../types/HorizonStaking/HorizonStaking'
import { Indexer, GraphNetwork } from '../types/schema'
import { calculateCapacities, createOrLoadDataService, createOrLoadEpoch, createOrLoadGraphNetwork, createOrLoadIndexer, createOrLoadProvision, updateAdvancedIndexerMetrics } from './helpers/helpers'
import { Indexer, GraphNetwork, ThawRequest } from '../types/schema'
import { calculateCapacities, createOrLoadDataService, createOrLoadEpoch, createOrLoadGraphAccount, createOrLoadGraphNetwork, createOrLoadIndexer, createOrLoadProvision, updateAdvancedIndexerMetrics } from './helpers/helpers'
import {
ProvisionCreated,
ProvisionIncreased,
Expand Down Expand Up @@ -177,17 +177,23 @@ export function handleProvisionSlashed(event: ProvisionSlashed): void {
}

export function handleThawRequestCreated(event: ThawRequestCreated): void {
// To Do
let dataService = createOrLoadDataService(event.params.verifier)
let indexer = Indexer.load(event.params.serviceProvider.toHexString())!
let owner = createOrLoadGraphAccount(event.params.owner, event.block.timestamp)

let request = new ThawRequest(event.params.thawRequestId.toHexString())
request.indexer = indexer.id
request.service = dataService.id
request.owner = owner.id
request.shares = event.params.shares
request.tokens = BigInt.fromI32(0)
request.thawingUntil = event.params.thawingUntil
request.save()
}

export function handleThawRequestFulfilled(event: ThawRequestFulfilled): void {
// To Do
}

export function handleThawRequestsFulfilled(event: ThawRequestsFulfilled): void {
// To Do
}

export function handleThawingPeriodCleared(event: ThawingPeriodCleared): void {
// To Do
}
let request = ThawRequest.load(event.params.thawRequestId.toHexString())
request.tokens = event.params.tokens
request.valid = event.params.valid
request.save()
}
4 changes: 0 additions & 4 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,6 @@ dataSources:
handler: handleThawRequestCreated
- event: ThawRequestFulfilled(indexed bytes32,uint256,uint256,uint64,bool)
handler: handleThawRequestFulfilled
- event: ThawRequestsFulfilled(indexed address,indexed address,indexed address,uint256,uint256,uint8)
handler: handleThawRequestsFulfilled
- event: ThawingPeriodCleared()
handler: handleThawingPeriodCleared
- kind: ethereum/contract
name: Curation
network: {{network}}
Expand Down

0 comments on commit 6ce272c

Please sign in to comment.