feat: metadata update and token changes on subgraph (#135)

* feat: add entity and handler.

* merge: reverse lookup and ap auto approval.

* feat: update the token entity on metadata changes.

* merge: develop. fix conflicts.

* fix: tests.
This commit is contained in:
Shredder 2023-02-24 16:39:25 +03:30 committed by GitHub
parent 2ae7666648
commit d7841717ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 112 additions and 167 deletions

View File

@ -31,11 +31,10 @@ contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl, Fl
string gitRepository, string gitRepository,
string logo, string logo,
uint24 color, uint24 color,
bool accessPointAutoApprovalSettings, bool accessPointAutoApproval,
address indexed minter, address indexed minter,
address indexed owner address indexed owner
); );
event MetadataUpdate(uint256 indexed _tokenId, string key, string value, address indexed triggeredBy); event MetadataUpdate(uint256 indexed _tokenId, string key, string value, address indexed triggeredBy);
event MetadataUpdate(uint256 indexed _tokenId, string key, uint24 value, address indexed triggeredBy); event MetadataUpdate(uint256 indexed _tokenId, string key, uint24 value, address indexed triggeredBy);
event MetadataUpdate(uint256 indexed _tokenId, string key, string[2] value, address indexed triggeredBy); event MetadataUpdate(uint256 indexed _tokenId, string key, string[2] value, address indexed triggeredBy);
@ -43,7 +42,11 @@ contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl, Fl
event NewAccessPoint(string apName, uint256 indexed tokenId, address indexed owner); event NewAccessPoint(string apName, uint256 indexed tokenId, address indexed owner);
event RemoveAccessPoint(string apName, uint256 indexed tokenId, address indexed owner); event RemoveAccessPoint(string apName, uint256 indexed tokenId, address indexed owner);
event ChangeAccessPointAutoApproval(uint256 indexed token, bool indexed settings, address indexed triggeredBy); event ChangeAccessPointAutoApproval(
uint256 indexed token,
bool indexed settings,
address indexed triggeredBy
);
event ChangeAccessPointScore(string apName, uint256 indexed tokenId, uint256 score, address indexed triggeredBy); event ChangeAccessPointScore(string apName, uint256 indexed tokenId, uint256 score, address indexed triggeredBy);

View File

@ -6,7 +6,7 @@ import "../TestBase.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {FleekAccessControl} from "contracts/FleekAccessControl.sol"; import {FleekAccessControl} from "contracts/FleekAccessControl.sol";
import "../../../../contracts/FleekERC721.sol"; import "../../../../contracts/FleekERC721.sol";
import "./ApBase.sol"; import './ApBase.sol';
contract Test_FleekERC721_AccessPoint is Test_FleekERC721_Base, APConstants { contract Test_FleekERC721_AccessPoint is Test_FleekERC721_Base, APConstants {
using Strings for address; using Strings for address;
@ -37,7 +37,7 @@ contract Test_FleekERC721_AccessPoint is Test_FleekERC721_Base, APConstants {
string memory accessPointName = "accesspoint.com"; string memory accessPointName = "accesspoint.com";
CuT.addAccessPoint(tokenId, accessPointName); CuT.addAccessPoint(tokenId, accessPointName);
CuT.removeAccessPoint(accessPointName); CuT.removeAccessPoint(accessPointName);
APConstants.assertAccessPointJSON( APConstants.assertAccessPointJSON(
accessPointName, accessPointName,
"0", "0",
@ -65,6 +65,7 @@ contract Test_FleekERC721_AccessPoint is Test_FleekERC721_Base, APConstants {
function test_increaseAccessPointScore() public { function test_increaseAccessPointScore() public {
string memory accessPointName = "accesspoint.com"; string memory accessPointName = "accesspoint.com";
CuT.addAccessPoint(tokenId, accessPointName); CuT.addAccessPoint(tokenId, accessPointName);
APConstants.assertAccessPointJSON( APConstants.assertAccessPointJSON(
accessPointName, accessPointName,
"0", "0",

View File

@ -67,6 +67,7 @@ contract Test_FleekERC721_AccessPoint is Test_FleekERC721_Base, APConstants {
function test_increaseAccessPointScore() public { function test_increaseAccessPointScore() public {
string memory accessPointName = "accesspoint.com"; string memory accessPointName = "accesspoint.com";
CuT.addAccessPoint(tokenId, accessPointName); CuT.addAccessPoint(tokenId, accessPointName);
APConstants.assertAccessPointJSON( APConstants.assertAccessPointJSON(
accessPointName, accessPointName,
"0", "0",

View File

@ -204,7 +204,10 @@ describe('FleekERC721.AccessPoints.AutoApprovalOff', () => {
it('should token owner be able to change the auto approval settings to on', async () => { it('should token owner be able to change the auto approval settings to on', async () => {
const { contract, tokenId, owner } = fixture; const { contract, tokenId, owner } = fixture;
await contract.connect(owner).setAccessPointAutoApproval(tokenId, true);
await contract
.connect(owner)
.setAccessPointAutoApproval(tokenId, true);
await contract.addAccessPoint(tokenId, 'accesspoint.com'); await contract.addAccessPoint(tokenId, 'accesspoint.com');

View File

@ -11,12 +11,6 @@ export const TestConstants = Object.freeze({
REJECTED: 2, REJECTED: 2,
REMOVED: 3, REMOVED: 3,
}, },
AccessPointStatus: {
DRAFT: 0,
APPROVED: 1,
REJECTED: 2,
REMOVED: 3,
},
MintParams: { MintParams: {
name: 'Fleek Test App', name: 'Fleek Test App',
description: 'Fleek Test App Description', description: 'Fleek Test App Description',

View File

@ -49,7 +49,7 @@ type NewMint @entity(immutable: true) {
gitRepository: String! # string gitRepository: String! # string
logo: String! logo: String!
color: Int! color: Int!
accessPointAutoApprovalSettings: Boolean! accessPointAutoApproval: Boolean!
triggeredBy: Bytes! # address triggeredBy: Bytes! # address
tokenOwner: Owner! # address tokenOwner: Owner! # address
blockNumber: BigInt! blockNumber: BigInt!
@ -57,61 +57,14 @@ type NewMint @entity(immutable: true) {
transactionHash: Bytes! transactionHash: Bytes!
} }
type NewBuild @entity(immutable: true) { type MetadataUpdate @entity(immutable: true) {
id: Bytes! id: Bytes!
token: BigInt! # uint256 tokenId: BigInt!
commitHash: String! # string key: String!
triggeredBy: Bytes! # address stringValue: String
blockNumber: BigInt! uint24Value: Int
blockTimestamp: BigInt! doubleStringValue: [String!]!
transactionHash: Bytes! byAddress: Bytes!
}
type NewTokenDescription @entity(immutable: true) {
id: Bytes!
token: BigInt! # uint256
description: String! # string
triggeredBy: Bytes! # address
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}
type NewTokenENS @entity(immutable: true) {
id: Bytes!
token: BigInt! # uint256
ENS: String! # string
triggeredBy: Bytes! # address
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}
type NewTokenExternalURL @entity(immutable: true) {
id: Bytes!
token: BigInt! # uint256
externalURL: String! # string
triggeredBy: Bytes! # address
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}
type NewTokenLogo @entity(immutable: true) {
id: Bytes!
token: BigInt! # uint256
logo: String! # string
triggeredBy: Bytes! # address
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}
type NewTokenName @entity(immutable: true) {
id: Bytes!
token: BigInt! # uint256
name: String! # string
triggeredBy: Bytes! # address
blockNumber: BigInt! blockNumber: BigInt!
blockTimestamp: BigInt! blockTimestamp: BigInt!
transactionHash: Bytes! transactionHash: Bytes!
@ -159,7 +112,7 @@ type Token @entity {
ENS: String! ENS: String!
logo: String! logo: String!
color: Int! color: Int!
accessPointAutoApprovalSettings: Boolean! accessPointAutoApproval: Boolean!
owner: Owner! owner: Owner!
mintedBy: Bytes! mintedBy: Bytes!
controllers: [Controller!] controllers: [Controller!]

View File

@ -4,13 +4,9 @@ import {
ApprovalForAll as ApprovalForAllEvent, ApprovalForAll as ApprovalForAllEvent,
CollectionRoleGranted as CollectionRoleGrantedEvent, CollectionRoleGranted as CollectionRoleGrantedEvent,
CollectionRoleRevoked as CollectionRoleRevokedEvent, CollectionRoleRevoked as CollectionRoleRevokedEvent,
FleekNFA, MetadataUpdate as MetadataUpdateEvent,
NewBuild as NewBuildEvent, MetadataUpdate1 as MetadataUpdateEvent1,
NewTokenDescription as NewTokenDescriptionEvent, MetadataUpdate2 as MetadataUpdateEvent2,
NewTokenENS as NewTokenENSEvent,
NewTokenExternalURL as NewTokenExternalURLEvent,
NewTokenLogo as NewTokenLogoEvent,
NewTokenName as NewTokenNameEvent,
TokenRoleGranted as TokenRoleGrantedEvent, TokenRoleGranted as TokenRoleGrantedEvent,
TokenRoleRevoked as TokenRoleRevokedEvent, TokenRoleRevoked as TokenRoleRevokedEvent,
Transfer as TransferEvent, Transfer as TransferEvent,
@ -25,13 +21,8 @@ import {
CollectionRoleRevoked, CollectionRoleRevoked,
Controller, Controller,
GitRepository as GitRepositoryEntity, GitRepository as GitRepositoryEntity,
NewBuild, MetadataUpdate,
NewMint, NewMint,
NewTokenDescription,
NewTokenENS,
NewTokenExternalURL,
NewTokenLogo,
NewTokenName,
Owner, Owner,
Token, Token,
TokenRoleGranted, TokenRoleGranted,
@ -155,7 +146,6 @@ export function handleCollectionRoleRevoked(
store.remove('CollectionOwner', event.params.toAddress.toHexString()); store.remove('CollectionOwner', event.params.toAddress.toHexString());
} }
} }
export function handleNewMint(event: NewMintEvent): void { export function handleNewMint(event: NewMintEvent): void {
let newMintEntity = new NewMint( let newMintEntity = new NewMint(
event.transaction.hash.concatI32(event.logIndex.toI32()) event.transaction.hash.concatI32(event.logIndex.toI32())
@ -169,8 +159,8 @@ export function handleNewMint(event: NewMintEvent): void {
let commitHash = event.params.commitHash; let commitHash = event.params.commitHash;
let logo = event.params.logo; let logo = event.params.logo;
let color = event.params.color; let color = event.params.color;
let accessPointAutoApprovalSettings = let accessPointAutoApproval =
event.params.accessPointAutoApprovalSettings; event.params.accessPointAutoApproval;
let tokenId = event.params.tokenId; let tokenId = event.params.tokenId;
let ownerAddress = event.params.owner; let ownerAddress = event.params.owner;
@ -183,8 +173,8 @@ export function handleNewMint(event: NewMintEvent): void {
newMintEntity.gitRepository = gitRepository; newMintEntity.gitRepository = gitRepository;
newMintEntity.logo = logo; newMintEntity.logo = logo;
newMintEntity.color = color; newMintEntity.color = color;
newMintEntity.accessPointAutoApprovalSettings = newMintEntity.accessPointAutoApproval =
accessPointAutoApprovalSettings; accessPointAutoApproval;
newMintEntity.triggeredBy = event.params.minter; newMintEntity.triggeredBy = event.params.minter;
newMintEntity.tokenOwner = ownerAddress; newMintEntity.tokenOwner = ownerAddress;
newMintEntity.blockNumber = event.block.number; newMintEntity.blockNumber = event.block.number;
@ -224,7 +214,7 @@ export function handleNewMint(event: NewMintEvent): void {
token.commitHash = commitHash; token.commitHash = commitHash;
token.logo = logo; token.logo = logo;
token.color = color; token.color = color;
token.accessPointAutoApprovalSettings = accessPointAutoApprovalSettings; token.accessPointAutoApproval = accessPointAutoApproval;
token.owner = ownerAddress; token.owner = ownerAddress;
token.mintTransaction = event.transaction.hash.concatI32( token.mintTransaction = event.transaction.hash.concatI32(
event.logIndex.toI32() event.logIndex.toI32()
@ -239,98 +229,108 @@ export function handleNewMint(event: NewMintEvent): void {
token.save(); token.save();
} }
export function handleNewBuild(event: NewBuildEvent): void { export function handleMetadataUpdateWithStringValue(event: MetadataUpdateEvent): void {
let entity = new NewBuild( /**
* Metadata handled here:
* setTokenExternalURL
* setTokenENS
* setTokenName
* setTokenDescription
* setTokenLogo
* */
let entity = new MetadataUpdate(
event.transaction.hash.concatI32(event.logIndex.toI32()) event.transaction.hash.concatI32(event.logIndex.toI32())
); );
entity.token = event.params.tokenId;
entity.commitHash = event.params.commitHash.toString();
entity.triggeredBy = event.params.triggeredBy;
entity.tokenId = event.params._tokenId;
entity.key = event.params.key;
entity.stringValue = event.params.value;
entity.blockNumber = event.block.number; entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp; entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash; entity.transactionHash = event.transaction.hash;
entity.save(); entity.save();
// UPDATE TOKEN
let token = Token.load(Bytes.fromByteArray(Bytes.fromBigInt(event.params._tokenId)));
if (token) {
if (event.params.key == 'externalURL') {
token.externalURL = event.params.value;
} else if (event.params.key == 'ENS') {
token.ENS = event.params.value;
} else if (event.params.key == 'name') {
token.name = event.params.value;
} else if (event.params.key == 'description') {
token.description = event.params.value;
} else {
// logo
token.logo = event.params.value;
}
token.save();
}
} }
export function handleNewTokenDescription( export function handleMetadataUpdateWithDoubleStringValue(event: MetadataUpdateEvent2): void {
event: NewTokenDescriptionEvent /**
): void { * setTokenBuild
let entity = new NewTokenDescription( */
let entity = new MetadataUpdate(
event.transaction.hash.concatI32(event.logIndex.toI32()) event.transaction.hash.concatI32(event.logIndex.toI32())
); );
entity.token = event.params.tokenId;
entity.description = event.params.description.toString();
entity.triggeredBy = event.params.triggeredBy;
entity.key = event.params.key;
entity.tokenId = event.params._tokenId;
entity.doubleStringValue = event.params.value;
entity.blockNumber = event.block.number; entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp; entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash; entity.transactionHash = event.transaction.hash;
entity.save(); entity.save();
// UPDATE TOKEN
let token = Token.load(Bytes.fromByteArray(Bytes.fromBigInt(event.params._tokenId)));
if (token) {
if (event.params.key == 'build') {
let gitRepositoryEntity = GitRepositoryEntity.load(event.params.value[1]);
if (!gitRepositoryEntity) {
// Create a new gitRepository entity
gitRepositoryEntity = new GitRepositoryEntity(event.params.value[1]);
}
token.commitHash = event.params.value[0];
token.gitRepository = event.params.value[1];
token.save();
gitRepositoryEntity.save();
}
}
} }
export function handleNewTokenENS(event: NewTokenENSEvent): void { export function handleMetadataUpdateWithIntValue(event: MetadataUpdateEvent1): void {
let entity = new NewTokenENS( /**
* setTokenColor
*/
let entity = new MetadataUpdate(
event.transaction.hash.concatI32(event.logIndex.toI32()) event.transaction.hash.concatI32(event.logIndex.toI32())
); );
entity.token = event.params.tokenId;
entity.ENS = event.params.ENS.toString();
entity.triggeredBy = event.params.triggeredBy;
entity.key = event.params.key;
entity.tokenId = event.params._tokenId;
entity.uint24Value = event.params.value;
entity.blockNumber = event.block.number; entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp; entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash; entity.transactionHash = event.transaction.hash;
entity.save(); entity.save();
}
export function handleNewTokenExternalURL( let token = Token.load(Bytes.fromByteArray(Bytes.fromBigInt(event.params._tokenId)));
event: NewTokenExternalURLEvent
): void {
let entity = new NewTokenExternalURL(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
entity.token = event.params.tokenId;
entity.externalURL = event.params.externalURL.toString();
entity.triggeredBy = event.params.triggeredBy;
entity.blockNumber = event.block.number; if (token) {
entity.blockTimestamp = event.block.timestamp; if (event.params.key == 'color') {
entity.transactionHash = event.transaction.hash; token.color = event.params.value;
}
entity.save(); token.save();
} }
export function handleNewTokenLogo(event: NewTokenLogoEvent): void {
let entity = new NewTokenLogo(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
entity.token = event.params.tokenId;
entity.logo = event.params.logo.toString();
entity.triggeredBy = event.params.triggeredBy;
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;
entity.save();
}
export function handleNewTokenName(event: NewTokenNameEvent): void {
let entity = new NewTokenName(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
entity.token = event.params.tokenId;
entity.name = event.params.name.toString();
entity.triggeredBy = event.params.triggeredBy;
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;
entity.save();
} }
export function handleTokenRoleGranted(event: TokenRoleGrantedEvent): void { export function handleTokenRoleGranted(event: TokenRoleGrantedEvent): void {

View File

@ -18,12 +18,8 @@ dataSources:
- ApprovalForAll - ApprovalForAll
- CollectionRoleGranted - CollectionRoleGranted
- CollectionRoleRevoked - CollectionRoleRevoked
- NewBuild - MetadataUpdate
- NewTokenDescription - NewMint
- NewTokenENS
- NewTokenExternalURL
- NewTokenImage
- NewTokenName
- TokenRoleGranted - TokenRoleGranted
- TokenRoleRevoked - TokenRoleRevoked
- Transfer - Transfer
@ -40,24 +36,18 @@ dataSources:
handler: handleApproval handler: handleApproval
- event: ApprovalForAll(indexed address,indexed address,bool) - event: ApprovalForAll(indexed address,indexed address,bool)
handler: handleApprovalForAll handler: handleApprovalForAll
- event: MetadataUpdate(indexed uint256,string,string,indexed address)
handler: handleMetadataUpdateWithStringValue
- event: MetadataUpdate(indexed uint256,string,string[2],indexed address)
handler: handleMetadataUpdateWithDoubleStringValue
- event: MetadataUpdate(indexed uint256,string,uint24,indexed address)
handler: handleMetadataUpdateWithIntValue
- event: CollectionRoleGranted(indexed uint8,indexed address,address) - event: CollectionRoleGranted(indexed uint8,indexed address,address)
handler: handleCollectionRoleGranted handler: handleCollectionRoleGranted
- event: CollectionRoleRevoked(indexed uint8,indexed address,address) - event: CollectionRoleRevoked(indexed uint8,indexed address,address)
handler: handleCollectionRoleRevoked handler: handleCollectionRoleRevoked
- event: NewMint(indexed uint256,string,string,string,string,string,string,string,uint24,bool,indexed address,indexed address) - event: NewMint(indexed uint256,string,string,string,string,string,string,string,uint24,bool,indexed address,indexed address)
handler: handleNewMint handler: handleNewMint
- event: NewBuild(indexed uint256,string,indexed address)
handler: handleNewBuild
- event: NewTokenDescription(indexed uint256,string,indexed address)
handler: handleNewTokenDescription
- event: NewTokenENS(indexed uint256,string,indexed address)
handler: handleNewTokenENS
- event: NewTokenExternalURL(indexed uint256,string,indexed address)
handler: handleNewTokenExternalURL
- event: NewTokenLogo(indexed uint256,string,indexed address)
handler: handleNewTokenLogo
- event: NewTokenName(indexed uint256,string,indexed address)
handler: handleNewTokenName
- event: TokenRoleGranted(indexed uint256,indexed uint8,indexed address,address) - event: TokenRoleGranted(indexed uint256,indexed uint8,indexed address,address)
handler: handleTokenRoleGranted handler: handleTokenRoleGranted
- event: TokenRoleRevoked(indexed uint256,indexed uint8,indexed address,address) - event: TokenRoleRevoked(indexed uint256,indexed uint8,indexed address,address)