From 66d5e19fd0eb46487adc285a7d2c8e99f8c823c1 Mon Sep 17 00:00:00 2001 From: Dan Oved Date: Thu, 18 Jan 2024 10:39:08 -0800 Subject: [PATCH] Change to use a factory version entity, that gets created in upgrade event (#76) * Change to use a factory version entity, that gets created in upgrade event * added zora sepolia * fix 721 type * updated start blocks * remove name and rename to factory version * configured zora mainet --- config/zora-mainnet.json | 7 ++++++ config/zora-sepolia.json | 7 ++++++ config/zora-testnet.json | 4 ++-- schema.graphql | 24 +++++++++++++-------- src/ERC1155Mappings/factoryMappings.ts | 21 ++++++++++++++++-- src/ERC1155Mappings/upgradeGateMappings.ts | 24 +++------------------ src/ERC721Mappings/ERC721FactoryMappings.ts | 22 +++++++++++++++++-- 7 files changed, 73 insertions(+), 36 deletions(-) diff --git a/config/zora-mainnet.json b/config/zora-mainnet.json index 31e7e2c..988b4ad 100644 --- a/config/zora-mainnet.json +++ b/config/zora-mainnet.json @@ -45,5 +45,12 @@ "startBlock": "6686902", "version": "1" } + ], + "upgradeGate1155": [ + { + "address": "0xbC50029836A59A4E5e1Bb8988272F46ebA0F9900", + "startBlock": "4663885", + "version": "1" + } ] } \ No newline at end of file diff --git a/config/zora-sepolia.json b/config/zora-sepolia.json index ec0eb68..84ee37a 100644 --- a/config/zora-sepolia.json +++ b/config/zora-sepolia.json @@ -35,5 +35,12 @@ "startBlock": "992417", "version": "1" } + ], + "upgradeGate1155": [ + { + "address": "0xbC50029836A59A4E5e1Bb8988272F46ebA0F9900", + "startBlock": "300562", + "version": "1" + } ] } diff --git a/config/zora-testnet.json b/config/zora-testnet.json index fb703c1..0cb486e 100644 --- a/config/zora-testnet.json +++ b/config/zora-testnet.json @@ -4,7 +4,7 @@ "factories1155": [ { "address": "0x6a357139C1bcDcf0B3AB9bC447932dDdcb956703", - "startBlock": "1", + "startBlock": "110449", "version": "1" }, { @@ -16,7 +16,7 @@ "factories721": [ { "address": "0x1Fc0BAE875C2CF2262BEc25B16d96814D37025AC", - "startBlock": "1", + "startBlock": "112670", "version": "1" }, { diff --git a/schema.graphql b/schema.graphql index bd60425..30415ba 100644 --- a/schema.graphql +++ b/schema.graphql @@ -90,6 +90,20 @@ type TokenSale @entity { # drop: ERC721Drop! # } +type ContractVersion @entity { + # id is implementation address + id: Bytes! + version: String +} + +type FactoryVersion @entity { + id: Bytes! + + version: String! + type: String + creatorContract: ContractVersion +} + type Upgrade @entity { # Begin – default data block id: ID! @@ -100,18 +114,10 @@ type Upgrade @entity { # End – default data block impl: Bytes - version: String! - creatorContractImpl: Bytes + factoryVersion: FactoryVersion! type: String } -type ContractVersion @entity { - # id is implementation address - id: Bytes! - version: String - name: String -} - type UpgradePath @entity { id: ID! diff --git a/src/ERC1155Mappings/factoryMappings.ts b/src/ERC1155Mappings/factoryMappings.ts index ab8300c..f13364e 100644 --- a/src/ERC1155Mappings/factoryMappings.ts +++ b/src/ERC1155Mappings/factoryMappings.ts @@ -5,6 +5,8 @@ import { } from "../../generated/ZoraNFTCreatorFactory1155V1/ZoraCreator1155FactoryImpl"; import { + ContractVersion, + FactoryVersion, Upgrade, ZoraCreate1155Factory, ZoraCreateContract, @@ -108,15 +110,30 @@ export function handle1155FactoryUpgraded(event: Upgraded): void { factory.redeemMinterStrategyAddress = redeemFactory.value; } + const factoryVersion = new FactoryVersion(event.params.implementation); + factoryVersion.version = creator.contractVersion(); + factoryVersion.type = '1155Factory'; + + const creatorContractImpl = creator.try_zora1155Impl().value; + + if (creatorContractImpl) { + const contractVersion = new ContractVersion(creatorContractImpl); + contractVersion.version = factoryVersion.version; + + contractVersion.save(); + factoryVersion.creatorContract = contractVersion.id; + } + + factoryVersion.save(); + const txn = makeTransaction(event); upgrade.txn = txn; upgrade.block = event.block.number; upgrade.timestamp = event.block.timestamp; upgrade.impl = event.params.implementation; - upgrade.version = creator.contractVersion(); + upgrade.factoryVersion = factoryVersion.id; // zora1155Impl didn't exist on all versions of the contract, so this // handles the case it doesnt exist. - upgrade.creatorContractImpl = creator.try_zora1155Impl().value; upgrade.address = event.address; upgrade.type = "1155Factory"; diff --git a/src/ERC1155Mappings/upgradeGateMappings.ts b/src/ERC1155Mappings/upgradeGateMappings.ts index 7866ba3..b9f3926 100644 --- a/src/ERC1155Mappings/upgradeGateMappings.ts +++ b/src/ERC1155Mappings/upgradeGateMappings.ts @@ -3,37 +3,19 @@ import { } from "../../generated/UpgradePathsV1/UpgradeGate"; import { - ContractVersion, UpgradePath, } from "../../generated/schema"; -import { ZoraCreator1155Impl } from "../../generated/templates/ZoraCreator1155Impl/ZoraCreator1155Impl"; -import { Address, Bytes, store } from "@graphprotocol/graph-ts"; - -function getContractVersion(address: Bytes): ContractVersion { - const contractVersion = new ContractVersion(address); - - const zoraCreator1155Impl = ZoraCreator1155Impl.bind(address as Address); - - contractVersion.version = zoraCreator1155Impl.try_contractVersion().value; - contractVersion.name = zoraCreator1155Impl.try_name().value; - - return contractVersion; -} +import { Bytes, store } from "@graphprotocol/graph-ts"; function upgradePathId(from: Bytes, to: Bytes): string { return `${from.toHex()}-${to.toHex()}`; } export function handleUpgradeRegistered(event: UpgradeRegistered): void { - const fromVersion = getContractVersion(event.params.baseImpl); - const toVersion = getContractVersion(event.params.upgradeImpl); - const upgradePath = new UpgradePath(upgradePathId(event.params.baseImpl, event.params.upgradeImpl)); - upgradePath.from = fromVersion.id; - upgradePath.to = toVersion.id; + upgradePath.from = event.params.baseImpl; + upgradePath.to = event.params.upgradeImpl; - fromVersion.save(); - toVersion.save(); upgradePath.save(); } diff --git a/src/ERC721Mappings/ERC721FactoryMappings.ts b/src/ERC721Mappings/ERC721FactoryMappings.ts index a6790ac..c57c84b 100644 --- a/src/ERC721Mappings/ERC721FactoryMappings.ts +++ b/src/ERC721Mappings/ERC721FactoryMappings.ts @@ -10,6 +10,8 @@ import { ZoraCreateToken, RoyaltyConfig, KnownRenderer, + FactoryVersion, + ContractVersion, } from "../../generated/schema"; import { @@ -82,12 +84,28 @@ export function handleFactoryUpgraded(event: Upgraded): void { const txn = makeTransaction(event); + const factoryVersion = new FactoryVersion(event.params.implementation); + factoryVersion.version = creator.contractVersion().toString(); + factoryVersion.type = '721Factory'; + + const creatorContractImpl = creator.try_implementation().value; + + if (creatorContractImpl) { + const contractVersion = new ContractVersion(creatorContractImpl); + contractVersion.version = factoryVersion.version; + + contractVersion.save(); + + factoryVersion.creatorContract = contractVersion.id; + } + + factoryVersion.save(); + upgrade.txn = txn; upgrade.block = event.block.number; upgrade.timestamp = event.block.timestamp; upgrade.impl = event.params.implementation; - upgrade.version = creator.contractVersion().toString(); - upgrade.creatorContractImpl = creator.implementation(); + upgrade.factoryVersion = factoryVersion.id; upgrade.address = event.address; upgrade.type = "721Factory";