Skip to content

Commit

Permalink
Split mappings main file
Browse files Browse the repository at this point in the history
Threshold Subgraph recieves events from several sources (contracts). So
a logical division of events handlers can be each contract.

To achieve this, the generic "mappings.ts" file have been splitted in
"pre-app.ts" and "staking.ts".

Also, TokenStaking entities list in subgraph manifest has been updated.
  • Loading branch information
manumonti committed Jun 8, 2022
1 parent c2834fa commit b6ff905
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
12 changes: 6 additions & 6 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ type Epoch @entity {
stakes: [EpochStake!]!
}

type EpochCounter @entity {
# Singleton entity, id = epoch-counter
id: ID!
count: Int!
}

type MinStakeAmount @entity {
id: ID!
amount: BigInt!
updatedAt: BigInt!
blockNumber: BigInt!
}

type EpochCounter @entity {
# Singleton entity, id = epoch-counter
id: ID!
count: Int!
}

interface Delegation {
# The delegatee address
id: ID!
Expand Down
21 changes: 0 additions & 21 deletions src/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { crypto, ByteArray, BigInt, log } from "@graphprotocol/graph-ts"
import {
OperatorBonded,
OperatorConfirmed,
} from "../generated/SimplePREApplication/SimplePREApplication"
import {
Staked,
ToppedUp,
Expand Down Expand Up @@ -275,23 +271,6 @@ export function handleDelegateVotesChanged(event: DelegateVotesChanged): void {
daoMetric.save()
}

export function handleOperatorBonded(event: OperatorBonded): void {
const preOperator = new PREOperator(
event.params.stakingProvider.toHexString()
)
preOperator.operator = event.params.operator
preOperator.save()
}

export function handleOperatorConfirmed(event: OperatorConfirmed): void {
const preOperator = new PREOperator(
event.params.stakingProvider.toHexString()
)
preOperator.operator = event.params.operator
preOperator.confirmationTimestamp = event.block.timestamp
preOperator.save()
}

export function handleMinStakeAmountChanged(
event: MinimumStakeAmountSet
): void {
Expand Down
22 changes: 22 additions & 0 deletions src/pre-app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
OperatorBonded,
OperatorConfirmed,
} from "../generated/SimplePREApplication/SimplePREApplication"
import { PREOperator } from "../generated/schema"

export function handleOperatorBonded(event: OperatorBonded): void {
const preOperator = new PREOperator(
event.params.stakingProvider.toHexString()
)
preOperator.operator = event.params.operator
preOperator.save()
}

export function handleOperatorConfirmed(event: OperatorConfirmed): void {
const preOperator = new PREOperator(
event.params.stakingProvider.toHexString()
)
preOperator.operator = event.params.operator
preOperator.confirmationTimestamp = event.block.timestamp
preOperator.save()
}
14 changes: 8 additions & 6 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ dataSources:
apiVersion: 0.0.5
language: wasm/assemblyscript
entities:
- Staked
- ToppedUp
- Unstaked
- DelegateChanged
- Account
- StakeData
- EpochStake
- Epoch
- EpochCounter
- MinStakeAmount
abis:
- name: TokenStaking
file: ./abis/TokenStaking.json
Expand All @@ -34,7 +36,7 @@ dataSources:
handler: handleDelegateChanged
- event: DelegateVotesChanged(indexed address,uint256,uint256)
handler: handleDelegateVotesChanged
file: ./src/mapping.ts
file: ./src/staking.ts
- kind: ethereum
name: ThresholdToken
network: mainnet
Expand Down Expand Up @@ -80,4 +82,4 @@ dataSources:
handler: handleOperatorConfirmed
- event: OperatorBonded(indexed address,indexed address,uint256)
handler: handleOperatorBonded
file: ./src/mapping.ts
file: ./src/pre-app.ts

0 comments on commit b6ff905

Please sign in to comment.