From 2a2da6d20b4c79ad1f86be3bcef4401b54d7311a Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Thu, 12 Jan 2023 19:59:10 -0300 Subject: [PATCH] feat: initial refactor of graphNetwork entity to hold L1 Block --- config/addresses.template.ts | 2 + config/arbitrumGoerliAddressScript.ts | 2 +- config/goerliAddressScript.ts | 2 +- config/mainnetAddressScript.ts | 2 +- config/mainnetArbitrumAddressScript.ts | 2 +- config/rinkebyAddressScript.ts | 42 ----------------- schema.graphql | 2 + src/mappings/curation.ts | 13 +++--- src/mappings/disputeManager.ts | 3 +- src/mappings/epochManager.ts | 13 +++--- src/mappings/gns.ts | 28 +++++++----- src/mappings/graphToken.ts | 6 +-- src/mappings/helpers.ts | 55 ++++++++++++++++++++-- src/mappings/l1Gateway.ts | 3 +- src/mappings/l2Gateway.ts | 3 +- src/mappings/rewardsManager.ts | 8 ++-- src/mappings/staking.ts | 58 +++++++++++++++--------- src/mappings/tokenLockWallets/manager.ts | 6 ++- subgraph.template.yaml | 43 ++++++++++++++++++ 19 files changed, 187 insertions(+), 106 deletions(-) delete mode 100644 config/rinkebyAddressScript.ts diff --git a/config/addresses.template.ts b/config/addresses.template.ts index c336e32c..d4840cf4 100644 --- a/config/addresses.template.ts +++ b/config/addresses.template.ts @@ -19,6 +19,7 @@ export class Addresses { l1GraphTokenGateway: string l2GraphTokenGateway: string ethereumDIDRegistry: string + isL1: boolean } // AS compiler does not like const @@ -42,4 +43,5 @@ export let addresses: Addresses = { l1GraphTokenGateway: '{{l1GraphTokenGateway}}', l2GraphTokenGateway: '{{l2GraphTokenGateway}}', ethereumDIDRegistry: '{{ethereumDIDRegistry}}', + isL1: {{isL1}}, } diff --git a/config/arbitrumGoerliAddressScript.ts b/config/arbitrumGoerliAddressScript.ts index e7a74f68..2f8ab32c 100644 --- a/config/arbitrumGoerliAddressScript.ts +++ b/config/arbitrumGoerliAddressScript.ts @@ -28,6 +28,7 @@ export let addresses: Addresses = { l1GraphTokenGateway: '', l2GraphTokenGateway: '{{arbgor.L2GraphTokenGateway.address}}', ethereumDIDRegistry: '{{arbgor.IEthereumDIDRegistry.address}}', + isL1: false, } const main = (): void => { @@ -37,7 +38,6 @@ const main = (): void => { output.bridgeBlockNumber = '1023272' // Bridge deployment block output.network = 'arbitrum-goerli' output.useTokenLockManager = false - output.isL1 = false fs.writeFileSync(__dirname + '/generatedAddresses.json', JSON.stringify(output, null, 2)) } catch (e) { console.log(`Error saving artifacts: ${e.message}`) diff --git a/config/goerliAddressScript.ts b/config/goerliAddressScript.ts index 7f42f753..f602b134 100644 --- a/config/goerliAddressScript.ts +++ b/config/goerliAddressScript.ts @@ -28,6 +28,7 @@ export let addresses: Addresses = { l1GraphTokenGateway: '{{goerli.L1GraphTokenGateway.address}}', l2GraphTokenGateway: '', ethereumDIDRegistry: '{{goerli.IEthereumDIDRegistry.address}}', + isL1: true, } const main = (): void => { @@ -38,7 +39,6 @@ const main = (): void => { output.network = 'goerli' output.tokenLockManager = '0x9a7a54e86560f4304d8862Ea00F45D1090c59ac8' // we don't have one, this is rinkebys' output.useTokenLockManager = true - output.isL1 = true fs.writeFileSync(__dirname + '/generatedAddresses.json', JSON.stringify(output, null, 2)) } catch (e) { console.log(`Error saving artifacts: ${e.message}`) diff --git a/config/mainnetAddressScript.ts b/config/mainnetAddressScript.ts index 10f88c5c..15d16047 100644 --- a/config/mainnetAddressScript.ts +++ b/config/mainnetAddressScript.ts @@ -28,6 +28,7 @@ export let addresses: Addresses = { l1GraphTokenGateway: '{{mainnet.L1GraphTokenGateway.address}}', l2GraphTokenGateway: '', ethereumDIDRegistry: '{{mainnet.IEthereumDIDRegistry.address}}', + isL1: true, } const main = (): void => { @@ -38,7 +39,6 @@ const main = (): void => { output.bridgeBlockNumber = '16083315' // TBD output.tokenLockManager = '0xFCf78AC094288D7200cfdB367A8CD07108dFa128' output.useTokenLockManager = true - output.isL1 = true fs.writeFileSync(__dirname + '/generatedAddresses.json', JSON.stringify(output, null, 2)) } catch (e) { console.log(`Error saving artifacts: ${e.message}`) diff --git a/config/mainnetArbitrumAddressScript.ts b/config/mainnetArbitrumAddressScript.ts index 2494ab92..909be5d2 100644 --- a/config/mainnetArbitrumAddressScript.ts +++ b/config/mainnetArbitrumAddressScript.ts @@ -28,6 +28,7 @@ export let addresses: Addresses = { l1GraphTokenGateway: '', l2GraphTokenGateway: '{{arbitrum.L2GraphTokenGateway.address}}', ethereumDIDRegistry: '{{arbitrum.IEthereumDIDRegistry.address}}', + isL1: false, } const main = (): void => { @@ -41,7 +42,6 @@ const main = (): void => { if(output.ethereumDIDRegistry == '') { output.ethereumDIDRegistry = '0xdCa7EF03e98e0DC2B855bE647C39ABe984fcF21B' // since the package doens't have it yet } - output.isL1 = false fs.writeFileSync(__dirname + '/generatedAddresses.json', JSON.stringify(output, null, 2)) } catch (e) { console.log(`Error saving artifacts: ${e.message}`) diff --git a/config/rinkebyAddressScript.ts b/config/rinkebyAddressScript.ts deleted file mode 100644 index ec256b9b..00000000 --- a/config/rinkebyAddressScript.ts +++ /dev/null @@ -1,42 +0,0 @@ -import * as fs from 'fs' -import * as mustache from 'mustache' -import * as networkAddresses from '@graphprotocol/contracts/addresses.json' -import { Addresses } from './addresses.template' - -// mustache doesn't like numbered object keys -// eslint-disable-next-line @typescript-eslint/no-explicit-any -let renameAddresses: any = networkAddresses -renameAddresses['rinkeby'] = networkAddresses['4'] - -export let addresses: Addresses = { - controller: '{{rinkeby.Controller.address}}', - graphToken: '{{rinkeby.GraphToken.address}}', - epochManager: '{{rinkeby.EpochManager.address}}', - disputeManager: '{{rinkeby.DisputeManager.address}}', - staking: '{{rinkeby.Staking.address}}', - curation: '{{rinkeby.Curation.address}}', - rewardsManager: '{{rinkeby.RewardsManager.address}}', - serviceRegistry: '{{rinkeby.ServiceRegistry.address}}', - gns: '{{rinkeby.GNS.address}}', - ens: '{{rinkeby.IENS.address}}', - ensPublicResolver: '{{rinkeby.IPublicResolver.address}}', - blockNumber: '', - network: '', - tokenLockManager: '', - subgraphNFT: '{{rinkeby.SubgraphNFT.address}}', -} - -const main = (): void => { - try { - let output = JSON.parse(mustache.render(JSON.stringify(addresses), renameAddresses)) - output.blockNumber = '7560000' // Hardcoded from first contract deploy of the latest phase - output.network = 'rinkeby' - output.tokenLockManager = '0x7B0809048370E69aC0C0844E1188Ecd3aB3A0C5f' - output.useTokenLockManager = true - fs.writeFileSync(__dirname + '/generatedAddresses.json', JSON.stringify(output, null, 2)) - } catch (e) { - console.log(`Error saving artifacts: ${e.message}`) - } -} - -main() diff --git a/schema.graphql b/schema.graphql index 1efd8f0c..9c80f0e3 100644 --- a/schema.graphql +++ b/schema.graphql @@ -207,6 +207,8 @@ type GraphNetwork @entity { totalGRTDepositedConfirmed: BigInt! "Total amount of GRT withdrawn from the L2 gateway. Note that the actual amount claimed in L1 might be lower due to outbound transactions not finalized." totalGRTWithdrawn: BigInt! + "Block number for L1. Only implemented for L2 deployments to properly reflect the L1 block used for timings" + currentL1BlockNumber: BigInt } """ diff --git a/src/mappings/curation.ts b/src/mappings/curation.ts index e0676f90..476109be 100644 --- a/src/mappings/curation.ts +++ b/src/mappings/curation.ts @@ -18,6 +18,7 @@ import { batchUpdateSubgraphSignalledTokens, } from './helpers' import { zeroBD } from './utils' +import { addresses } from '../../config/addresses' /** * @dev handleStaked @@ -52,7 +53,7 @@ export function handleSignalled(event: Signalled): void { let signal = createOrLoadSignal( id, subgraphDeploymentID, - event.block.number.toI32(), + (addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32(), event.block.timestamp.toI32(), ) @@ -66,7 +67,7 @@ export function handleSignalled(event: Signalled): void { signal.signal = signal.signal.plus(event.params.signal) signal.lastUpdatedAt = event.block.timestamp.toI32() - signal.lastUpdatedAtBlock = event.block.number.toI32() + signal.lastUpdatedAtBlock = (addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32() signal.averageCostBasis = signal.averageCostBasis.plus(event.params.tokens.toBigDecimal()) let gnsSignalNewAmount = signal.signal.toBigDecimal() @@ -110,7 +111,7 @@ export function handleSignalled(event: Signalled): void { batchUpdateSubgraphSignalledTokens(deployment as SubgraphDeployment) // Update epoch - let epoch = createOrLoadEpoch(event.block.number) + let epoch = createOrLoadEpoch((addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!)) epoch.signalledTokens = epoch.signalledTokens.plus( event.params.tokens.minus(event.params.curationTax), ) @@ -146,7 +147,7 @@ export function handleSignalled(event: Signalled): void { let signalTransaction = new SignalTransaction( event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()), ) - signalTransaction.blockNumber = event.block.number.toI32() + signalTransaction.blockNumber = (addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32() signalTransaction.timestamp = event.block.timestamp.toI32() signalTransaction.signer = event.params.curator.toHexString() signalTransaction.type = 'MintSignal' @@ -179,7 +180,7 @@ export function handleBurned(event: Burned): void { // Note - if you immediately deposited and then withdrew, you would lose 5%, and you were // realize this loss by seeing unsignaled tokens being 95 and signalled 100 signal.lastUpdatedAt = event.block.timestamp.toI32() - signal.lastUpdatedAtBlock = event.block.number.toI32() + signal.lastUpdatedAtBlock = (addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32() signal.unsignalledTokens = signal.unsignalledTokens.plus(event.params.tokens) signal.signal = signal.signal.minus(event.params.signal) @@ -269,7 +270,7 @@ export function handleBurned(event: Burned): void { let signalTransaction = new SignalTransaction( event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()), ) - signalTransaction.blockNumber = event.block.number.toI32() + signalTransaction.blockNumber = (addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32() signalTransaction.timestamp = event.block.timestamp.toI32() signalTransaction.signer = event.params.curator.toHexString() signalTransaction.type = 'BurnSignal' diff --git a/src/mappings/disputeManager.ts b/src/mappings/disputeManager.ts index 3926422e..05864ee4 100644 --- a/src/mappings/disputeManager.ts +++ b/src/mappings/disputeManager.ts @@ -11,6 +11,7 @@ import { DisputeManager, } from '../types/DisputeManager/DisputeManager' import { DisputeManagerStitched } from '../types/DisputeManager/DisputeManagerStitched' +import { createOrLoadGraphNetwork } from './helpers' // This handles Single query and Conflicting disputes export function handleQueryDisputeCreated(event: QueryDisputeCreated): void { @@ -150,7 +151,7 @@ export function handleDisputeLinked(event: DisputeLinked): void { */ export function handleParameterUpdated(event: ParameterUpdated): void { let parameter = event.params.param - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let disputeManager = DisputeManagerStitched.bind(event.address as Address) if (parameter == 'arbitrator') { diff --git a/src/mappings/epochManager.ts b/src/mappings/epochManager.ts index 9f7144fd..958fc158 100644 --- a/src/mappings/epochManager.ts +++ b/src/mappings/epochManager.ts @@ -1,13 +1,14 @@ import { GraphNetwork } from '../types/schema' import { EpochRun, EpochLengthUpdate } from '../types/EpochManager/EpochManager' -import { createOrLoadEpoch, createEpoch } from './helpers' +import { createOrLoadEpoch, createEpoch, createOrLoadGraphNetwork } from './helpers' +import { addresses } from '../../config/addresses' /** * @dev handleEpochRun * - updates the last run epoch */ export function handleEpochRun(event: EpochRun): void { - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.lastRunEpoch = event.params.epoch.toI32() graphNetwork.save() } @@ -17,26 +18,26 @@ export function handleEpochRun(event: EpochRun): void { * - updates the length and the last block and epoch it happened */ export function handleEpochLengthUpdate(event: EpochLengthUpdate): void { - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) // This event is emitted on EpochManagers constructor, so it has some special logic to handle // initialization here if (graphNetwork.epochLength == 0) { // Will only ever be 0 on initialization in the contracts graphNetwork.epochLength = event.params.epochLength.toI32() - graphNetwork.lastLengthUpdateBlock = event.block.number.toI32() + graphNetwork.lastLengthUpdateBlock = (addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32() graphNetwork.currentEpoch = 0 graphNetwork.epochCount = 1 graphNetwork.lastLengthUpdateEpoch = graphNetwork.currentEpoch graphNetwork.save() - createEpoch(event.block.number.toI32(), graphNetwork.epochLength, graphNetwork.currentEpoch) + createEpoch((addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32(), graphNetwork.epochLength, graphNetwork.currentEpoch) // return here so it doesn't run the normal handler return } // This returns a new epoch, or current epoch, with the old epoch length - let epoch = createOrLoadEpoch(event.block.number) + let epoch = createOrLoadEpoch((addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!)) // Check that the endBlock for the current epoch match what it should based on the // changed epoch length diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index 056077b0..47edd667 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -55,8 +55,10 @@ import { duplicateOrUpdateSubgraphWithNewID, duplicateOrUpdateSubgraphVersionWithNewID, duplicateOrUpdateNameSignalWithNewID, + createOrLoadGraphNetwork } from './helpers' import { fetchSubgraphMetadata, fetchSubgraphVersionMetadata } from './metadataHelpers' +import { addresses } from '../../config/addresses' export function handleSetDefaultName(event: SetDefaultName): void { let graphAccount = createOrLoadGraphAccount(event.params.graphAccount, event.block.timestamp) @@ -303,7 +305,7 @@ export function handleSubgraphDeprecated(event: SubgraphDeprecated): void { let subgraphDuplicate = duplicateOrUpdateSubgraphWithNewID(subgraph, oldID, 1) subgraphDuplicate.save() - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.activeSubgraphCount = graphNetwork.activeSubgraphCount - 1 graphNetwork.save() @@ -333,6 +335,7 @@ export function handleNameSignalEnabled(event: NameSignalEnabled): void { } export function handleNSignalMinted(event: NSignalMinted): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let curatorID = event.params.nameCurator.toHexString() let oldID = joinID([ event.params.graphAccount.toHexString(), @@ -433,7 +436,7 @@ export function handleNSignalMinted(event: NSignalMinted): void { curator.activeCombinedSignalCount = curator.activeCombinedSignalCount + 1 if (curator.activeCombinedSignalCount == 1) { - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.activeCuratorCount = graphNetwork.activeCuratorCount + 1 graphNetwork.save() } @@ -444,7 +447,7 @@ export function handleNSignalMinted(event: NSignalMinted): void { let nSignalTransaction = new NameSignalTransaction( event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()), ) - nSignalTransaction.blockNumber = event.block.number.toI32() + nSignalTransaction.blockNumber = (addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32() nSignalTransaction.timestamp = event.block.timestamp.toI32() nSignalTransaction.signer = event.params.nameCurator.toHexString() nSignalTransaction.type = 'MintNSignal' @@ -456,6 +459,7 @@ export function handleNSignalMinted(event: NSignalMinted): void { } export function handleNSignalBurned(event: NSignalBurned): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let curatorID = event.params.nameCurator.toHexString() let oldID = joinID([ event.params.graphAccount.toHexString(), @@ -554,7 +558,7 @@ export function handleNSignalBurned(event: NSignalBurned): void { curator.activeCombinedSignalCount = curator.activeCombinedSignalCount - 1 if (curator.activeCombinedSignalCount == 0) { - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.activeCuratorCount = graphNetwork.activeCuratorCount - 1 graphNetwork.save() } @@ -566,7 +570,7 @@ export function handleNSignalBurned(event: NSignalBurned): void { let nSignalTransaction = new NameSignalTransaction( event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()), ) - nSignalTransaction.blockNumber = event.block.number.toI32() + nSignalTransaction.blockNumber = (addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32() nSignalTransaction.timestamp = event.block.timestamp.toI32() nSignalTransaction.signer = event.params.nameCurator.toHexString() nSignalTransaction.type = 'BurnNSignal' @@ -726,7 +730,7 @@ export function handleGRTWithdrawn(event: GRTWithdrawn): void { */ export function handleParameterUpdated(event: ParameterUpdated): void { let parameter = event.params.param - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let gns = GNS.bind(event.address) if (parameter == 'ownerTaxPercentage') { @@ -804,7 +808,7 @@ export function handleSubgraphDeprecatedV2(event: SubgraphDeprecated1): void { subgraphDuplicate.save() } - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.activeSubgraphCount = graphNetwork.activeSubgraphCount - 1 graphNetwork.save() @@ -857,6 +861,7 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1) // handler: handleNSignalMintedV2 export function handleNSignalMintedV2(event: SignalMinted): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let curatorID = event.params.curator.toHexString() let bigIntID = event.params.subgraphID let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID) @@ -959,7 +964,7 @@ export function handleNSignalMintedV2(event: SignalMinted): void { curator.activeCombinedSignalCount = curator.activeCombinedSignalCount + 1 if (curator.activeCombinedSignalCount == 1) { - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.activeCuratorCount = graphNetwork.activeCuratorCount + 1 graphNetwork.save() } @@ -970,7 +975,7 @@ export function handleNSignalMintedV2(event: SignalMinted): void { let nSignalTransaction = new NameSignalTransaction( event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()), ) - nSignalTransaction.blockNumber = event.block.number.toI32() + nSignalTransaction.blockNumber = (addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32() nSignalTransaction.timestamp = event.block.timestamp.toI32() nSignalTransaction.signer = event.params.curator.toHexString() nSignalTransaction.type = 'MintNSignal' @@ -985,6 +990,7 @@ export function handleNSignalMintedV2(event: SignalMinted): void { // handler: handleNSignalBurnedV2 export function handleNSignalBurnedV2(event: SignalBurned): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let bigIntID = event.params.subgraphID let subgraphID = convertBigIntSubgraphIDToBase58(bigIntID) let subgraph = Subgraph.load(subgraphID)! @@ -1084,7 +1090,7 @@ export function handleNSignalBurnedV2(event: SignalBurned): void { curator.activeCombinedSignalCount = curator.activeCombinedSignalCount - 1 if (curator.activeCombinedSignalCount == 0) { - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.activeCuratorCount = graphNetwork.activeCuratorCount - 1 graphNetwork.save() } @@ -1096,7 +1102,7 @@ export function handleNSignalBurnedV2(event: SignalBurned): void { let nSignalTransaction = new NameSignalTransaction( event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()), ) - nSignalTransaction.blockNumber = event.block.number.toI32() + nSignalTransaction.blockNumber = (addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!).toI32() nSignalTransaction.timestamp = event.block.timestamp.toI32() nSignalTransaction.signer = event.params.curator.toHexString() nSignalTransaction.type = 'BurnNSignal' diff --git a/src/mappings/graphToken.ts b/src/mappings/graphToken.ts index b02bc39a..bd0a6a70 100644 --- a/src/mappings/graphToken.ts +++ b/src/mappings/graphToken.ts @@ -1,5 +1,5 @@ import { Approval, Transfer, GraphToken } from '../types/GraphToken/GraphToken' -import { createOrLoadGraphAccount } from './helpers' +import { createOrLoadGraphAccount, createOrLoadGraphNetwork } from './helpers' import { GraphNetwork } from '../types/schema' /** @@ -10,7 +10,7 @@ import { GraphNetwork } from '../types/schema' export function handleTransfer(event: Transfer): void { // The first transaction ever emitted in the network is the minting of GRT // And with this, we instantiate GraphNetwork // TODO - can probably LOAD here now - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let staking = graphNetwork.staking let curation = graphNetwork.curation let gns = graphNetwork.gns @@ -60,7 +60,7 @@ export function handleTransfer(event: Transfer): void { } export function handleApproval(event: Approval): void { - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let staking = graphNetwork.staking let curation = graphNetwork.curation let gns = graphNetwork.gns diff --git a/src/mappings/helpers.ts b/src/mappings/helpers.ts index f7bfcc9b..aa167209 100644 --- a/src/mappings/helpers.ts +++ b/src/mappings/helpers.ts @@ -1,4 +1,13 @@ -import { BigInt, ByteArray, Address, Bytes, crypto, log, BigDecimal } from '@graphprotocol/graph-ts' +import { + BigInt, + ByteArray, + Address, + Bytes, + crypto, + log, + BigDecimal, + dataSource, +} from '@graphprotocol/graph-ts' import { SubgraphDeployment, GraphNetwork, @@ -22,6 +31,7 @@ import { } from '../types/schema' import { ENS } from '../types/GNS/ENS' import { Controller } from '../types/Controller/Controller' +import { EpochManager } from '../types/EpochManager/EpochManager' import { fetchSubgraphDeploymentManifest } from './metadataHelpers' import { addresses } from '../../config/addresses' @@ -510,7 +520,16 @@ export function createOrLoadGraphNetwork( graphNetwork.epochLength = 0 graphNetwork.lastRunEpoch = 0 graphNetwork.lastLengthUpdateEpoch = 0 - graphNetwork.lastLengthUpdateBlock = blockNumber.toI32() // start it first block it was created + if (addresses.isL1) { + graphNetwork.lastLengthUpdateBlock = blockNumber.toI32() // Use chain native block + } else { + let epochManagerAddress = dataSource.address() + let contract = EpochManager.bind(epochManagerAddress) + let response = contract.try_blockNum() + if (!response.reverted) { + graphNetwork.lastLengthUpdateBlock = response.value.toI32() // Use L1 block + } + } graphNetwork.currentEpoch = 0 graphNetwork.epochCount = 0 @@ -535,6 +554,9 @@ export function createOrLoadGraphNetwork( graphNetwork.save() } + if(!addresses.isL1) { + graphNetwork = updateL1BlockNumber(graphNetwork) + } return graphNetwork as GraphNetwork } @@ -894,7 +916,11 @@ export function getSubgraphID(graphAccount: Address, subgraphNumber: BigInt): Bi return bigIntRepresentation } -export function duplicateOrUpdateSubgraphWithNewID(entity: Subgraph, newID: String, newEntityVersion: i32): Subgraph { +export function duplicateOrUpdateSubgraphWithNewID( + entity: Subgraph, + newID: String, + newEntityVersion: i32, +): Subgraph { let subgraph = Subgraph.load(newID) if (subgraph == null) { subgraph = new Subgraph(newID) @@ -939,7 +965,11 @@ export function duplicateOrUpdateSubgraphWithNewID(entity: Subgraph, newID: Stri return subgraph as Subgraph } -export function duplicateOrUpdateSubgraphVersionWithNewID(entity: SubgraphVersion, newID: String, newEntityVersion: i32): SubgraphVersion { +export function duplicateOrUpdateSubgraphVersionWithNewID( + entity: SubgraphVersion, + newID: String, + newEntityVersion: i32, +): SubgraphVersion { let version = SubgraphVersion.load(newID) if (version == null) { version = new SubgraphVersion(newID) @@ -959,7 +989,11 @@ export function duplicateOrUpdateSubgraphVersionWithNewID(entity: SubgraphVersio return version as SubgraphVersion } -export function duplicateOrUpdateNameSignalWithNewID(entity: NameSignal, newID: String, newEntityVersion: i32): NameSignal { +export function duplicateOrUpdateNameSignalWithNewID( + entity: NameSignal, + newID: String, + newEntityVersion: i32, +): NameSignal { let signal = NameSignal.load(newID) if (signal == null) { signal = new NameSignal(newID) @@ -986,3 +1020,14 @@ export function duplicateOrUpdateNameSignalWithNewID(entity: NameSignal, newID: return signal as NameSignal } + +export function updateL1BlockNumber(graphNetwork: GraphNetwork): GraphNetwork { + let epochManagerAddress = dataSource.address() + let contract = EpochManager.bind(epochManagerAddress) + let response = contract.try_blockNum() + if (!response.reverted) { + graphNetwork.currentL1BlockNumber = response.value + graphNetwork.save() + } + return graphNetwork +} diff --git a/src/mappings/l1Gateway.ts b/src/mappings/l1Gateway.ts index 23c28ab3..92343cbc 100644 --- a/src/mappings/l1Gateway.ts +++ b/src/mappings/l1Gateway.ts @@ -1,8 +1,9 @@ import { DepositInitiated } from '../types/L1GraphTokenGateway/L1GraphTokenGateway' import { GraphNetwork } from '../types/schema' +import { createOrLoadGraphNetwork } from './helpers' export function handleDepositInitiated(event: DepositInitiated): void { - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.totalGRTDeposited = graphNetwork.totalGRTDeposited.plus(event.params.amount) graphNetwork.save() } diff --git a/src/mappings/l2Gateway.ts b/src/mappings/l2Gateway.ts index 8631ed97..9a9c109a 100644 --- a/src/mappings/l2Gateway.ts +++ b/src/mappings/l2Gateway.ts @@ -1,8 +1,9 @@ import { WithdrawalInitiated } from '../types/L2GraphTokenGateway/L2GraphTokenGateway' import { GraphNetwork } from '../types/schema' +import { createOrLoadGraphNetwork } from './helpers' export function handleWithdrawalInitiated(event: WithdrawalInitiated): void { - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.totalGRTWithdrawn = graphNetwork.totalGRTWithdrawn.plus(event.params.amount) graphNetwork.save() } diff --git a/src/mappings/rewardsManager.ts b/src/mappings/rewardsManager.ts index 8e9875f9..95014158 100644 --- a/src/mappings/rewardsManager.ts +++ b/src/mappings/rewardsManager.ts @@ -11,9 +11,12 @@ import { createOrLoadEpoch, updateAdvancedIndexerMetrics, updateDelegationExchangeRate, + createOrLoadGraphNetwork } from './helpers' +import { addresses } from '../../config/addresses' export function handleRewardsAssigned(event: RewardsAssigned): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let indexerID = event.params.indexer.toHexString() let allocationID = event.params.allocationID.toHexString() @@ -51,7 +54,7 @@ export function handleRewardsAssigned(event: RewardsAssigned): void { allocation.save() // Update epoch - let epoch = createOrLoadEpoch(event.block.number) + let epoch = createOrLoadEpoch((addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!)) epoch.totalRewards = epoch.totalRewards.plus(event.params.amount) epoch.totalIndexerRewards = epoch.totalIndexerRewards.plus(indexerIndexingRewards) epoch.totalDelegatorRewards = epoch.totalDelegatorRewards.plus(delegatorIndexingRewards) @@ -75,7 +78,6 @@ export function handleRewardsAssigned(event: RewardsAssigned): void { subgraphDeployment.save() // update graph network - let graphNetwork = GraphNetwork.load('1')! graphNetwork.totalIndexingRewards = graphNetwork.totalIndexingRewards.plus(event.params.amount) graphNetwork.totalIndexingIndexerRewards = graphNetwork.totalIndexingIndexerRewards.plus( indexerIndexingRewards, @@ -92,7 +94,7 @@ export function handleRewardsAssigned(event: RewardsAssigned): void { */ export function handleParameterUpdated(event: ParameterUpdated): void { let parameter = event.params.param - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let rewardsManager = RewardsManager.bind(event.address as Address) if (parameter == 'issuanceRate') { diff --git a/src/mappings/staking.ts b/src/mappings/staking.ts index 3e808e0c..c1185ad9 100644 --- a/src/mappings/staking.ts +++ b/src/mappings/staking.ts @@ -42,18 +42,23 @@ import { updateDelegationExchangeRate, calculatePricePerShare, batchUpdateSubgraphSignalledTokens, + createOrLoadGraphNetwork, } from './helpers' +import { addresses } from '../../config/addresses' export function handleDelegationParametersUpdated(event: DelegationParametersUpdated): void { let id = event.params.indexer.toHexString() // Quick fix to avoid creating new Indexer entities if they don't exist yet. let account = GraphAccount.load(id) if (account != null) { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let indexer = createOrLoadIndexer(id, event.block.timestamp) indexer.indexingRewardCut = event.params.indexingRewardCut.toI32() indexer.queryFeeCut = event.params.queryFeeCut.toI32() indexer.delegatorParameterCooldown = event.params.cooldownBlocks.toI32() - indexer.lastDelegationParameterUpdate = event.block.number.toI32() + indexer.lastDelegationParameterUpdate = ( + addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber! + ).toI32() indexer = updateAdvancedIndexerMetrics(indexer as Indexer) indexer.save() } @@ -66,6 +71,7 @@ export function handleDelegationParametersUpdated(event: DelegationParametersUpd * - updates the GraphNetwork total stake */ export function handleStakeDeposited(event: StakeDeposited): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) // update indexer let id = event.params.indexer.toHexString() let indexer = createOrLoadIndexer(id, event.block.timestamp) @@ -76,7 +82,6 @@ export function handleStakeDeposited(event: StakeDeposited): void { indexer.save() // Update graph network - let graphNetwork = GraphNetwork.load('1')! graphNetwork.totalTokensStaked = graphNetwork.totalTokensStaked.plus(event.params.tokens) if (previousStake == BigInt.fromI32(0)) { graphNetwork.stakedIndexersCount = graphNetwork.stakedIndexersCount + 1 @@ -84,7 +89,9 @@ export function handleStakeDeposited(event: StakeDeposited): void { graphNetwork.save() // Update epoch - let epoch = createOrLoadEpoch(event.block.number) + let epoch = createOrLoadEpoch( + addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!, + ) epoch.stakeDeposited = epoch.stakeDeposited.plus(event.params.tokens) epoch.save() } @@ -96,6 +103,7 @@ export function handleStakeDeposited(event: StakeDeposited): void { * get changed */ export function handleStakeLocked(event: StakeLocked): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) // update indexer let id = event.params.indexer.toHexString() let indexer = Indexer.load(id)! @@ -106,7 +114,6 @@ export function handleStakeLocked(event: StakeLocked): void { indexer.save() // update graph network - let graphNetwork = GraphNetwork.load('1')! graphNetwork.totalUnstakedTokensLocked = graphNetwork.totalUnstakedTokensLocked.plus( event.params.tokens, ) @@ -122,6 +129,7 @@ export function handleStakeLocked(event: StakeLocked): void { * - updates the GraphNetwork total stake */ export function handleStakeWithdrawn(event: StakeWithdrawn): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) // update indexer let id = event.params.indexer.toHexString() let indexer = Indexer.load(id)! @@ -133,7 +141,6 @@ export function handleStakeWithdrawn(event: StakeWithdrawn): void { indexer.save() // Update graph network - let graphNetwork = GraphNetwork.load('1')! graphNetwork.totalTokensStaked = graphNetwork.totalTokensStaked.minus(event.params.tokens) graphNetwork.totalUnstakedTokensLocked = graphNetwork.totalUnstakedTokensLocked.minus( event.params.tokens, @@ -146,6 +153,7 @@ export function handleStakeWithdrawn(event: StakeWithdrawn): void { * - update the Indexers stake */ export function handleStakeSlashed(event: StakeSlashed): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let id = event.params.indexer.toHexString() let indexer = Indexer.load(id)! @@ -154,7 +162,6 @@ export function handleStakeSlashed(event: StakeSlashed): void { // We need to call into stakes mapping, because locked tokens might have been // decremented, and this is not released in the event // To fix this we would need to indicate in the event how many locked tokens were released - let graphNetwork = GraphNetwork.load('1')! let staking = Staking.bind(event.address) let indexerStored = staking.stakes(event.params.indexer) indexer.lockedTokens = indexerStored.value2 @@ -220,7 +227,7 @@ export function handleStakeDelegated(event: StakeDelegated): void { delegator = Delegator.load(delegatorID) as Delegator // upgrade graph network - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.totalDelegatedTokens = graphNetwork.totalDelegatedTokens.plus(event.params.tokens) if (isStakeBecomingActive) { @@ -279,7 +286,7 @@ export function handleStakeDelegatedLocked(event: StakeDelegatedLocked): void { delegator.totalRealizedRewards = delegator.totalRealizedRewards.plus(realizedRewards) // upgrade graph network - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) graphNetwork.totalDelegatedTokens = graphNetwork.totalDelegatedTokens.minus(event.params.tokens) if (isStakeBecomingInactive) { @@ -314,6 +321,7 @@ export function handleStakeDelegatedWithdrawn(event: StakeDelegatedWithdrawn): v * - create a new channel */ export function handleAllocationCreated(event: AllocationCreated): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let subgraphDeploymentID = event.params.subgraphDeploymentID.toHexString() let indexerID = event.params.indexer.toHexString() let channelID = event.params.allocationID.toHexString() @@ -329,7 +337,6 @@ export function handleAllocationCreated(event: AllocationCreated): void { indexer.save() // update graph network - let graphNetwork = GraphNetwork.load('1')! graphNetwork.totalTokensAllocated = graphNetwork.totalTokensAllocated.plus(event.params.tokens) graphNetwork.save() @@ -348,7 +355,9 @@ export function handleAllocationCreated(event: AllocationCreated): void { allocation.effectiveAllocation = BigInt.fromI32(0) allocation.createdAtEpoch = event.params.epoch.toI32() allocation.createdAtBlockHash = event.block.hash - allocation.createdAtBlockNumber = event.block.number.toI32() + allocation.createdAtBlockNumber = ( + addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber! + ).toI32() allocation.queryFeesCollected = BigInt.fromI32(0) allocation.queryFeeRebates = BigInt.fromI32(0) allocation.curatorRewards = BigInt.fromI32(0) @@ -376,6 +385,7 @@ export function handleAllocationCreated(event: AllocationCreated): void { // Note - the name event.param.rebateFees is confusing. Rebate fees are better described // as query Fees. rebate is from cobbs douglas, which we get from claim() export function handleAllocationCollected(event: AllocationCollected): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let subgraphDeploymentID = event.params.subgraphDeploymentID.toHexString() let indexerID = event.params.indexer.toHexString() let allocationID = event.params.allocationID.toHexString() @@ -397,7 +407,9 @@ export function handleAllocationCollected(event: AllocationCollected): void { let taxedFees = event.params.tokens.minus(event.params.rebateFees.plus(event.params.curationFees)) // Update epoch - let epoch = createOrLoadEpoch(event.block.number) + let epoch = createOrLoadEpoch( + addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!, + ) epoch.totalQueryFees = epoch.totalQueryFees.plus(event.params.tokens) epoch.taxedQueryFees = epoch.taxedQueryFees.plus(taxedFees) epoch.queryFeesCollected = epoch.queryFeesCollected.plus(event.params.rebateFees) @@ -427,9 +439,7 @@ export function handleAllocationCollected(event: AllocationCollected): void { batchUpdateSubgraphSignalledTokens(deployment as SubgraphDeployment) - // update graph network - let graphNetwork = GraphNetwork.load('1')! graphNetwork.totalQueryFees = graphNetwork.totalQueryFees.plus(event.params.tokens) graphNetwork.totalIndexerQueryFeesCollected = graphNetwork.totalIndexerQueryFeesCollected.plus( event.params.rebateFees, @@ -453,6 +463,7 @@ export function handleAllocationCollected(event: AllocationCollected): void { * - update and close the channel */ export function handleAllocationClosed(event: AllocationClosed): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let indexerID = event.params.indexer.toHexString() let allocationID = event.params.allocationID.toHexString() @@ -477,7 +488,9 @@ export function handleAllocationClosed(event: AllocationClosed): void { allocation.activeForIndexer = null allocation.closedAtEpoch = event.params.epoch.toI32() allocation.closedAtBlockHash = event.block.hash - allocation.closedAtBlockNumber = event.block.number.toI32() + allocation.closedAtBlockNumber = ( + addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber! + ).toI32() allocation.effectiveAllocation = event.params.effectiveAllocation allocation.status = 'Closed' allocation.closedAt = event.block.timestamp.toI32() @@ -491,7 +504,9 @@ export function handleAllocationClosed(event: AllocationClosed): void { // update epoch - We do it here to have more epochs created, instead of seeing none created // Likely this problem would go away with a live network with long epochs // But we keep it here anyway. We might think of adding data in the future, like epoch.tokensClosed - let epoch = createOrLoadEpoch(event.block.number) + let epoch = createOrLoadEpoch( + addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!, + ) epoch.save() // update pool let pool = createOrLoadPool(event.params.epoch) @@ -513,7 +528,6 @@ export function handleAllocationClosed(event: AllocationClosed): void { deployment.save() // update graph network - let graphNetwork = GraphNetwork.load('1')! graphNetwork.totalTokensAllocated = graphNetwork.totalTokensAllocated.minus(event.params.tokens) graphNetwork.save() } @@ -527,6 +541,7 @@ export function handleAllocationClosed(event: AllocationClosed): void { * the other case, if it is restaked, it will be handled by handleStakeDeposited */ export function handleRebateClaimed(event: RebateClaimed): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let indexerID = event.params.indexer.toHexString() let allocationID = event.params.allocationID.toHexString() let subgraphDeploymentID = event.params.subgraphDeploymentID.toHexString() @@ -550,7 +565,9 @@ export function handleRebateClaimed(event: RebateClaimed): void { allocation.save() // Update epoch - let epoch = createOrLoadEpoch(event.block.number) + let epoch = createOrLoadEpoch( + addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!, + ) epoch.queryFeeRebates = epoch.queryFeeRebates.plus(event.params.tokens) epoch.save() @@ -565,7 +582,6 @@ export function handleRebateClaimed(event: RebateClaimed): void { subgraphDeployment.save() // update graph network - let graphNetwork = GraphNetwork.load('1')! graphNetwork.totalIndexerQueryFeeRebates = graphNetwork.totalIndexerQueryFeeRebates.plus( event.params.tokens, ) @@ -585,7 +601,7 @@ export function handleRebateClaimed(event: RebateClaimed): void { */ export function handleParameterUpdated(event: ParameterUpdated): void { let parameter = event.params.param - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let staking = Staking.bind(event.address) if (parameter == 'minimumIndexerStake') { @@ -639,7 +655,7 @@ export function handleSetOperator(event: SetOperator): void { } export function handleSlasherUpdate(event: SlasherUpdate): void { - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let slashers = graphNetwork.slashers if (slashers == null) { slashers = [] @@ -666,7 +682,7 @@ export function handleSlasherUpdate(event: SlasherUpdate): void { } export function handleAssetHolderUpdate(event: AssetHolderUpdate): void { - let graphNetwork = GraphNetwork.load('1')! + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let assetHolders = graphNetwork.assetHolders if (assetHolders == null) { assetHolders = [] diff --git a/src/mappings/tokenLockWallets/manager.ts b/src/mappings/tokenLockWallets/manager.ts index 123e8cd5..81d92c74 100644 --- a/src/mappings/tokenLockWallets/manager.ts +++ b/src/mappings/tokenLockWallets/manager.ts @@ -9,7 +9,8 @@ import { } from '../../types/GraphTokenLockManager/GraphTokenLockManager' import { GraphTokenLockWallet } from '../../types/templates' import { TokenManager, TokenLockWallet, AuthorizedFunction } from '../../types/schema' -import { createOrLoadGraphAccount } from '../helpers' +import { createOrLoadGraphAccount, createOrLoadGraphNetwork } from '../helpers' +import { addresses } from '../../../config/addresses' export function handleMasterCopyUpdated(event: MasterCopyUpdated): void { let tokenLock = TokenManager.load(event.address.toHexString()) @@ -36,6 +37,7 @@ export function handleMasterCopyUpdated(event: MasterCopyUpdated): void { * @param _vestingCliffTime Time the cliff vests, 0 if no cliff */ export function handleTokenLockCreated(event: TokenLockCreated): void { + let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let manager = TokenManager.load(event.address.toHexString())! manager.tokenLockCount = manager.tokenLockCount.plus(BigInt.fromI32(1)) manager.save() @@ -56,7 +58,7 @@ export function handleTokenLockCreated(event: TokenLockCreated): void { tokenLock.tokensWithdrawn = BigInt.fromI32(0) tokenLock.tokensRevoked = BigInt.fromI32(0) tokenLock.tokensReleased = BigInt.fromI32(0) - tokenLock.blockNumberCreated = event.block.number + tokenLock.blockNumberCreated = (addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!) tokenLock.txHash = event.transaction.hash if (event.params.revocable == 0) { tokenLock.revocable = 'NotSet' diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 61c7db90..a43e8c2b 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -21,6 +21,8 @@ dataSources: abis: - name: Controller file: ./node_modules/@graphprotocol/contracts/dist/abis/Controller.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: - event: SetContractProxy(indexed bytes32,address) handler: handleSetContractProxy @@ -57,6 +59,8 @@ dataSources: file: ./node_modules/@graphprotocol/contracts/dist/abis/IENS.json - name: ENSPublicResolver file: ./node_modules/@graphprotocol/contracts/dist/abis/IPublicResolver.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: # v1 - event: SubgraphPublished(indexed address,indexed uint256,indexed bytes32,bytes32) @@ -121,6 +125,8 @@ dataSources: abis: - name: SubgraphNFT file: ./node_modules/@graphprotocol/contracts/dist/abis/SubgraphNFT.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: - event: Transfer(indexed address,indexed address,indexed uint256) handler: handleTransfer @@ -141,6 +147,8 @@ dataSources: abis: - name: ServiceRegistry file: ./node_modules/@graphprotocol/contracts/dist/abis/ServiceRegistry.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: - event: ServiceRegistered(indexed address,string,string) handler: handleServiceRegistered @@ -232,6 +240,8 @@ dataSources: abis: - name: Curation file: ./node_modules/@graphprotocol/contracts/dist/abis/Curation.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: - event: Signalled(indexed address,indexed bytes32,uint256,uint256,uint256) handler: handleSignalled @@ -261,6 +271,8 @@ dataSources: abis: - name: GraphToken file: ./node_modules/@graphprotocol/contracts/dist/abis/GraphToken.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: - event: Transfer(indexed address,indexed address,uint256) handler: handleTransfer @@ -332,6 +344,8 @@ dataSources: abis: - name: RewardsManager file: ./node_modules/@graphprotocol/contracts/dist/abis/RewardsManager.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: - event: RewardsAssigned(indexed address,indexed address,uint256,uint256) handler: handleRewardsAssigned @@ -360,6 +374,8 @@ dataSources: file: ./node_modules/@graphprotocol/contracts/dist/abis/DisputeManager.json - name: DisputeManagerStitched file: ./abis/DisputeManagerStitched.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: - event: QueryDisputeCreated(indexed bytes32,indexed address,indexed address,uint256,bytes32,bytes) handler: handleQueryDisputeCreated @@ -393,6 +409,8 @@ dataSources: abis: - name: GraphTokenLockManager file: ./abis/GraphTokenLockManager.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: - event: MasterCopyUpdated(indexed address) handler: handleMasterCopyUpdated @@ -425,6 +443,8 @@ dataSources: abis: - name: L1GraphTokenGateway file: ./node_modules/@graphprotocol/contracts/dist/abis/L1GraphTokenGateway.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: - event: DepositInitiated(address,indexed address,indexed address,indexed uint256,uint256) handler: handleDepositInitiated @@ -447,9 +467,30 @@ dataSources: abis: - name: L2GraphTokenGateway file: ./node_modules/@graphprotocol/contracts/dist/abis/L2GraphTokenGateway.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: - event: WithdrawalInitiated(address,indexed address,indexed address,indexed uint256,uint256,uint256) handler: handleWithdrawalInitiated + # - kind: ethereum/contract + # name: BlockHandler + # network: {{network}} + # source: + # address: "{{epochManager}}" + # abi: EpochManager + # startBlock: {{blockNumber}} + # mapping: + # kind: ethereum/events + # apiVersion: 0.0.5 + # language: wasm/assemblyscript + # file: ./src/mappings/block.ts + # entities: + # - GraphNetwork + # abis: + # - name: EpochManager + # file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json + # blockHandlers: + # - handler: handleBlock {{/isL1}} templates: - kind: ethereum/contract @@ -467,6 +508,8 @@ templates: abis: - name: GraphTokenLockWallet file: ./abis/GraphTokenLockWallet.json + - name: EpochManager + file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json eventHandlers: - event: TokensReleased(indexed address,uint256) handler: handleTokensReleased