Skip to content

Commit

Permalink
Change to use a factory version entity, that gets created in upgrade …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
oveddan authored Jan 18, 2024
1 parent b1a11a1 commit 66d5e19
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 36 deletions.
7 changes: 7 additions & 0 deletions config/zora-mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,12 @@
"startBlock": "6686902",
"version": "1"
}
],
"upgradeGate1155": [
{
"address": "0xbC50029836A59A4E5e1Bb8988272F46ebA0F9900",
"startBlock": "4663885",
"version": "1"
}
]
}
7 changes: 7 additions & 0 deletions config/zora-sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,12 @@
"startBlock": "992417",
"version": "1"
}
],
"upgradeGate1155": [
{
"address": "0xbC50029836A59A4E5e1Bb8988272F46ebA0F9900",
"startBlock": "300562",
"version": "1"
}
]
}
4 changes: 2 additions & 2 deletions config/zora-testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"factories1155": [
{
"address": "0x6a357139C1bcDcf0B3AB9bC447932dDdcb956703",
"startBlock": "1",
"startBlock": "110449",
"version": "1"
},
{
Expand All @@ -16,7 +16,7 @@
"factories721": [
{
"address": "0x1Fc0BAE875C2CF2262BEc25B16d96814D37025AC",
"startBlock": "1",
"startBlock": "112670",
"version": "1"
},
{
Expand Down
24 changes: 15 additions & 9 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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!

Expand Down
21 changes: 19 additions & 2 deletions src/ERC1155Mappings/factoryMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
} from "../../generated/ZoraNFTCreatorFactory1155V1/ZoraCreator1155FactoryImpl";

import {
ContractVersion,
FactoryVersion,
Upgrade,
ZoraCreate1155Factory,
ZoraCreateContract,
Expand Down Expand Up @@ -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";

Expand Down
24 changes: 3 additions & 21 deletions src/ERC1155Mappings/upgradeGateMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
22 changes: 20 additions & 2 deletions src/ERC721Mappings/ERC721FactoryMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
ZoraCreateToken,
RoyaltyConfig,
KnownRenderer,
FactoryVersion,
ContractVersion,
} from "../../generated/schema";

import {
Expand Down Expand Up @@ -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";

Expand Down

0 comments on commit 66d5e19

Please sign in to comment.