diff --git a/schema.graphql b/schema.graphql index 4ee980c..77993b5 100644 --- a/schema.graphql +++ b/schema.graphql @@ -41,6 +41,7 @@ type CounterEntity @entity { subgraphL2TransferFinalizedEventCount: BigInt! curatorBalanceReceivedEventCount: BigInt! curatorBalanceReturnedToBeneficiaryEventCount: BigInt! + subgraphTransferredEventCount: BigInt! #interface counters eventCount: BigInt! subgraphEventCount: BigInt! @@ -595,6 +596,36 @@ type SubgraphL2TransferFinalizedEvent implements SubgraphEvent & Event @entity(i tx_cumulativeGasUsed: BigInt! } +type SubgraphTransferredEvent implements SubgraphEvent & GraphAccountEvent & Event + @entity(immutable: true) { + id: ID! + + timestamp: BigInt! + + blockNumber: BigInt! + + tx_hash: Bytes! + + typename: String! + + subgraph: Subgraph! + + from: GraphAccount! + + to: GraphAccount! + + "User that triggered the Event" + accounts: [GraphAccount!]! + + tx_gasLimit: BigInt! + + tx_gasPrice: BigInt! + + tx_gasUsed: BigInt! + + tx_cumulativeGasUsed: BigInt! +} + # Profile events (includes Indexer, Curator and Delegator events) interface GraphAccountEvent { diff --git a/src/mappings/gns.ts b/src/mappings/gns.ts index 879aeb6..5485450 100644 --- a/src/mappings/gns.ts +++ b/src/mappings/gns.ts @@ -21,6 +21,7 @@ import { SubgraphVersionUpdated, LegacySubgraphClaimed, GNS, + Transfer, } from '../types/GNS/GNS' import { @@ -41,6 +42,7 @@ import { ParameterUpdatedEvent, SetDefaultNameEvent, SubgraphVersionMetadataUpdatedEvent, + SubgraphTransferredEvent, } from '../types/schema' import { @@ -885,3 +887,48 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi export function handleLegacySubgraphClaimed(event: LegacySubgraphClaimed): void { let eventId = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()) } + +// - event: Transfer(indexed address,indexed address,indexed uint256) +// handler: handleTransfer + +export function handleTransfer(event: Transfer): void { + let eventId = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString()) + let newOwner = createOrLoadGraphAccount(event.params.to.toHexString()) + let oldOwner = createOrLoadGraphAccount(event.params.from.toHexString()) + let subgraphID = convertBigIntSubgraphIDToBase58(event.params.tokenId) + let accounts = new Array() + accounts.push(oldOwner.id) + accounts.push(newOwner.id) + + // Update subgraph v2 + let subgraph = createOrLoadSubgraph( + subgraphID, + event.transaction.from + ) + subgraph.owner = newOwner.id + subgraph.save() + + //todo + let otherEventEntity = new SubgraphTransferredEvent(eventId) + otherEventEntity.timestamp = event.block.timestamp + otherEventEntity.tx_gasLimit = event.transaction.gasLimit + otherEventEntity.tx_gasPrice = event.transaction.gasPrice + otherEventEntity.tx_gasUsed = event.receipt!.gasUsed + otherEventEntity.tx_cumulativeGasUsed = event.receipt!.cumulativeGasUsed + otherEventEntity.blockNumber = event.block.number + otherEventEntity.tx_hash = event.transaction.hash + otherEventEntity.typename = 'SubgraphTransferredEvent' + otherEventEntity.subgraph = subgraph.id + otherEventEntity.from = oldOwner.id + otherEventEntity.to = newOwner.id + otherEventEntity.accounts = accounts + otherEventEntity.save() + + let counter = getCounter() + counter.subgraphEventCount = counter.subgraphEventCount.plus(BIGINT_ONE) + counter.graphAccountEventCount = counter.graphAccountEventCount.plus(BIGINT_ONE) + counter.eventCount = counter.eventCount.plus(BIGINT_ONE) + counter.subgraphTransferredEventCount = counter.subgraphTransferredEventCount.plus(BIGINT_ONE) + counter.save() +} + diff --git a/src/mappings/helpers.ts b/src/mappings/helpers.ts index bb0bda2..aa9dfce 100644 --- a/src/mappings/helpers.ts +++ b/src/mappings/helpers.ts @@ -72,6 +72,7 @@ export function getCounter(): CounterEntity { counter.subgraphL2TransferFinalizedEventCount = BIGINT_ZERO counter.curatorBalanceReceivedEventCount = BIGINT_ZERO counter.curatorBalanceReturnedToBeneficiaryEventCount = BIGINT_ZERO + counter.subgraphTransferredEventCount = BIGINT_ZERO // Interface counters counter.eventCount = BIGINT_ZERO counter.subgraphEventCount = BIGINT_ZERO diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 87efa27..1d75a00 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -152,6 +152,33 @@ dataSources: handler: handleCuratorBalanceReturnedToBeneficiary receipt: true {{/isL1}} + - kind: ethereum/contract + name: SubgraphNFT + network: {{network}} + source: + address: "{{subgraphNFT}}" + abi: SubgraphNFT + startBlock: {{blockNumber}} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + file: ./src/mappings/gns.ts + entities: + - Subgraph + - SubgraphVersion + - SubgraphDeployment + - GraphAccount + - NameSignal + 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 + receipt: true - kind: ethereum/contract name: ServiceRegistry network: {{network}}