Skip to content

Commit

Permalink
feat: add l2 transferred totals tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmardefago committed Aug 31, 2023
1 parent 8409df2 commit 20631e0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
8 changes: 8 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ type GraphNetwork @entity {
"Asset holder for the protocol"
assetHolders: [Bytes!]

# Transfers to L2 totals
"Total amount of indexer stake transferred to L2"
totalTokensStakedTransferredToL2: BigInt!
"Total amount of delegated tokens transferred to L2"
totalDelegatedTokensTransferredToL2: BigInt!
"Total amount of delegated tokens transferred to L2"
totalSignalledTokensTransferredToL2: BigInt!

# Staking global aggregate values
"The total amount of GRT staked in the staking contract"
totalTokensStaked: BigInt!
Expand Down
3 changes: 3 additions & 0 deletions src/mappings/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ export function createOrLoadGraphNetwork(
graphNetwork.delegationTaxPercentage = 0
graphNetwork.rebateRatio = BigDecimal.fromString('0')

graphNetwork.totalTokensStakedTransferredToL2 = BigInt.fromI32(0)
graphNetwork.totalDelegatedTokensTransferredToL2 = BigInt.fromI32(0)
graphNetwork.totalSignalledTokensTransferredToL2 = BigInt.fromI32(0)
graphNetwork.totalTokensStaked = BigInt.fromI32(0)
graphNetwork.totalTokensClaimable = BigInt.fromI32(0)
graphNetwork.totalUnstakedTokensLocked = BigInt.fromI32(0)
Expand Down
15 changes: 15 additions & 0 deletions src/mappings/l1gns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
joinID,
convertBigIntSubgraphIDToBase58,
getAliasedL2SubgraphID,
createOrLoadGraphNetwork,
} from './helpers/helpers'

/*
Expand Down Expand Up @@ -68,6 +69,13 @@ export function handleSubgraphSentToL2(event: SubgraphSentToL2): void {
deployment.transferredToL2AtTx = event.transaction.hash.toHexString()
deployment.signalledTokensSentToL2 = deployment.signalledTokensSentToL2.plus(event.params._tokens)
deployment.save()

// upgrade graph network
let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address)
graphNetwork.totalTokensSignalled = graphNetwork.totalTokensSignalled.minus(event.params._tokens)
graphNetwork.totalTokensSignalledAutoMigrate = graphNetwork.totalTokensSignalledAutoMigrate.minus(event.params._tokens.toBigDecimal())
graphNetwork.totalSignalledTokensTransferredToL2 = graphNetwork.totalSignalledTokensTransferredToL2.plus(event.params._tokens)
graphNetwork.save()
}

/*
Expand Down Expand Up @@ -112,4 +120,11 @@ export function handleCuratorBalanceSentToL2(event: CuratorBalanceSentToL2): voi
let deployment = SubgraphDeployment.load(version.subgraphDeployment)!
deployment.signalledTokensSentToL2 = deployment.signalledTokensSentToL2.plus(event.params._tokens)
deployment.save()

// upgrade graph network
let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address)
graphNetwork.totalTokensSignalled = graphNetwork.totalTokensSignalled.minus(event.params._tokens)
graphNetwork.totalTokensSignalledAutoMigrate = graphNetwork.totalTokensSignalledAutoMigrate.minus(event.params._tokens.toBigDecimal())
graphNetwork.totalSignalledTokensTransferredToL2 = graphNetwork.totalSignalledTokensTransferredToL2.plus(event.params._tokens)
graphNetwork.save()
}
14 changes: 13 additions & 1 deletion src/mappings/l1staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../types/L1Staking/L1Staking'

import { Indexer, DelegatedStake, GraphNetwork } from '../types/schema'
import { calculateCapacities, joinID, updateAdvancedIndexerMetrics, updateDelegationExchangeRate } from './helpers/helpers'
import { calculateCapacities, createOrLoadGraphNetwork, joinID, updateAdvancedIndexerMetrics, updateDelegationExchangeRate } from './helpers/helpers'

/*
/// @dev Emitted when an indexer transfers their stake to L2.
Expand Down Expand Up @@ -37,6 +37,12 @@ export function handleIndexerStakeTransferredToL2(event: IndexerStakeTransferred
indexer = updateAdvancedIndexerMetrics(indexer as Indexer)
indexer = calculateCapacities(indexer as Indexer)
indexer.save()

// upgrade graph network
let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address)
graphNetwork.totalTokensStaked = graphNetwork.totalTokensStaked.minus(event.params.transferredStakeTokens)
graphNetwork.totalTokensStakedTransferredToL2 = graphNetwork.totalTokensStakedTransferredToL2.plus(event.params.transferredStakeTokens)
graphNetwork.save()
}
/*
/// @dev Emitted when a delegator transfers their delegation to L2
Expand Down Expand Up @@ -81,6 +87,12 @@ export function handleDelegationTransferredToL2(event: DelegationTransferredToL2
indexer = updateAdvancedIndexerMetrics(indexer as Indexer)
indexer = calculateCapacities(indexer as Indexer)
indexer.save()

// upgrade graph network
let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address)
graphNetwork.totalDelegatedTokens = graphNetwork.totalDelegatedTokens.minus(event.params.transferredDelegationTokens)
graphNetwork.totalDelegatedTokensTransferredToL2 = graphNetwork.totalDelegatedTokensTransferredToL2.plus(event.params.transferredDelegationTokens)
graphNetwork.save()
}

/*
Expand Down

0 comments on commit 20631e0

Please sign in to comment.