diff --git a/contracts/contracts/FleekERC721.sol b/contracts/contracts/FleekERC721.sol index ea0cce0..71df46f 100644 --- a/contracts/contracts/FleekERC721.sol +++ b/contracts/contracts/FleekERC721.sol @@ -16,30 +16,25 @@ contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl { using FleekStrings for FleekERC721.AccessPoint; using FleekStrings for string; - event NewBuild(uint256 indexed token, string indexed commitHash, address indexed triggeredBy); - event NewTokenName(uint256 indexed token, string indexed name, address indexed triggeredBy); - event NewTokenDescription(uint256 indexed token, string indexed description, address indexed triggeredBy); - event NewTokenLogo(uint256 indexed token, string indexed image, address indexed triggeredBy); - event NewTokenExternalURL(uint256 indexed token, string indexed externalURL, address indexed triggeredBy); - event NewTokenENS(uint256 indexed token, string indexed ENS, address indexed triggeredBy); - event NewTokenColor(uint256 indexed token, uint24 indexed color, address indexed triggeredBy); + event NewBuild(uint256 indexed tokenId, string commitHash, address indexed triggeredBy); + event NewTokenName(uint256 indexed tokenId, string name, address indexed triggeredBy); + event NewTokenDescription(uint256 indexed tokenId, string description, address indexed triggeredBy); + event NewTokenLogo(uint256 indexed tokenId, string logo, address indexed triggeredBy); + event NewTokenExternalURL(uint256 indexed tokenId, string externalURL, address indexed triggeredBy); + event NewTokenENS(uint256 indexed tokenId, string ENS, address indexed triggeredBy); + event NewTokenColor(uint256 indexed tokenId, uint24 color, address indexed triggeredBy); - event NewAccessPoint(string indexed apName, uint256 indexed tokenId, address indexed owner); - event RemoveAccessPoint(string indexed apName, uint256 indexed tokenId, address indexed owner); - event ChangeAccessPointScore( - string indexed apName, - uint256 indexed tokenId, - uint256 score, - address indexed triggeredBy - ); + event NewAccessPoint(string apName, uint256 indexed tokenId, address indexed owner); + event RemoveAccessPoint(string apName, uint256 indexed tokenId, address indexed owner); + event ChangeAccessPointScore(string apName, uint256 indexed tokenId, uint256 score, address indexed triggeredBy); event ChangeAccessPointNameVerify( - string indexed apName, + string apName, uint256 tokenId, bool indexed verified, address indexed triggeredBy ); event ChangeAccessPointContentVerify( - string indexed apName, + string apName, uint256 tokenId, bool indexed verified, address indexed triggeredBy diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index 6b11281..620c40d 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -78,10 +78,10 @@ type NewTokenExternalURL @entity(immutable: true) { transactionHash: Bytes! } -type NewTokenImage @entity(immutable: true) { +type NewTokenLogo @entity(immutable: true) { id: Bytes! token: BigInt! # uint256 - image: String! # string + logo: String! # string triggeredBy: Bytes! # address blockNumber: BigInt! blockTimestamp: BigInt! diff --git a/subgraph/src/fleek-nfa.ts b/subgraph/src/fleek-nfa.ts index 296256d..91ab371 100644 --- a/subgraph/src/fleek-nfa.ts +++ b/subgraph/src/fleek-nfa.ts @@ -9,7 +9,7 @@ import { NewTokenDescription as NewTokenDescriptionEvent, NewTokenENS as NewTokenENSEvent, NewTokenExternalURL as NewTokenExternalURLEvent, - NewTokenImage as NewTokenImageEvent, + NewTokenLogo as NewTokenLogoEvent, NewTokenName as NewTokenNameEvent, TokenRoleGranted as TokenRoleGrantedEvent, TokenRoleRevoked as TokenRoleRevokedEvent, @@ -21,12 +21,11 @@ import { CollectionRoleGranted, CollectionRoleRevoked, Controller, - Holder, NewBuild, NewTokenDescription, NewTokenENS, NewTokenExternalURL, - NewTokenImage, + NewTokenLogo, NewTokenName, Owner, Token, @@ -103,7 +102,7 @@ export function handleNewBuild(event: NewBuildEvent): void { let entity = new NewBuild( event.transaction.hash.concatI32(event.logIndex.toI32()) ); - entity.token = event.params.token; + entity.token = event.params.tokenId; entity.commitHash = event.params.commitHash.toString(); entity.triggeredBy = event.params.triggeredBy; @@ -120,7 +119,7 @@ export function handleNewTokenDescription( let entity = new NewTokenDescription( event.transaction.hash.concatI32(event.logIndex.toI32()) ); - entity.token = event.params.token; + entity.token = event.params.tokenId; entity.description = event.params.description.toString(); entity.triggeredBy = event.params.triggeredBy; @@ -135,7 +134,7 @@ export function handleNewTokenENS(event: NewTokenENSEvent): void { let entity = new NewTokenENS( event.transaction.hash.concatI32(event.logIndex.toI32()) ); - entity.token = event.params.token; + entity.token = event.params.tokenId; entity.ENS = event.params.ENS.toString(); entity.triggeredBy = event.params.triggeredBy; @@ -152,7 +151,7 @@ export function handleNewTokenExternalURL( let entity = new NewTokenExternalURL( event.transaction.hash.concatI32(event.logIndex.toI32()) ); - entity.token = event.params.token; + entity.token = event.params.tokenId; entity.externalURL = event.params.externalURL.toString(); entity.triggeredBy = event.params.triggeredBy; @@ -163,12 +162,12 @@ export function handleNewTokenExternalURL( entity.save(); } -export function handleNewTokenImage(event: NewTokenImageEvent): void { - let entity = new NewTokenImage( +export function handleNewTokenLogo(event: NewTokenLogoEvent): void { + let entity = new NewTokenLogo( event.transaction.hash.concatI32(event.logIndex.toI32()) ); - entity.token = event.params.token; - entity.image = event.params.image.toString(); + entity.token = event.params.tokenId; + entity.logo = event.params.logo.toString(); entity.triggeredBy = event.params.triggeredBy; entity.blockNumber = event.block.number; @@ -182,7 +181,7 @@ export function handleNewTokenName(event: NewTokenNameEvent): void { let entity = new NewTokenName( event.transaction.hash.concatI32(event.logIndex.toI32()) ); - entity.token = event.params.token; + entity.token = event.params.tokenId; entity.name = event.params.name.toString(); entity.triggeredBy = event.params.triggeredBy; diff --git a/subgraph/subgraph.yaml b/subgraph/subgraph.yaml index 149d5fd..1bb4586 100644 --- a/subgraph/subgraph.yaml +++ b/subgraph/subgraph.yaml @@ -32,7 +32,7 @@ dataSources: - Controller abis: - name: FleekNFA - file: ./abis/FleekNFA.json + file: ../contracts/artifacts/contracts/FleekERC721.sol/FleekERC721.json eventHandlers: - event: Approval(indexed address,indexed address,indexed uint256) handler: handleApproval @@ -42,17 +42,17 @@ dataSources: handler: handleCollectionRoleGranted - event: CollectionRoleRevoked(indexed uint8,indexed address,address) handler: handleCollectionRoleRevoked - - event: NewBuild(indexed uint256,indexed string,indexed address) + - event: NewBuild(indexed uint256,string,indexed address) handler: handleNewBuild - - event: NewTokenDescription(indexed uint256,indexed string,indexed address) + - event: NewTokenDescription(indexed uint256,string,indexed address) handler: handleNewTokenDescription - - event: NewTokenENS(indexed uint256,indexed string,indexed address) + - event: NewTokenENS(indexed uint256,string,indexed address) handler: handleNewTokenENS - - event: NewTokenExternalURL(indexed uint256,indexed string,indexed address) + - event: NewTokenExternalURL(indexed uint256,string,indexed address) handler: handleNewTokenExternalURL - - event: NewTokenImage(indexed uint256,indexed string,indexed address) - handler: handleNewTokenImage - - event: NewTokenName(indexed uint256,indexed string,indexed address) + - 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) handler: handleTokenRoleGranted diff --git a/subgraph/tests/.latest.json b/subgraph/tests/.latest.json new file mode 100644 index 0000000..d407eee --- /dev/null +++ b/subgraph/tests/.latest.json @@ -0,0 +1,4 @@ +{ + "version": "0.5.4", + "timestamp": 1675972891956 +} diff --git a/subgraph/tests/fleek-nfa.test.ts b/subgraph/tests/fleek-nfa.test.ts index fd27043..0640d9e 100644 --- a/subgraph/tests/fleek-nfa.test.ts +++ b/subgraph/tests/fleek-nfa.test.ts @@ -5,60 +5,494 @@ import { clearStore, beforeAll, afterAll, + logStore, + log, } from 'matchstick-as/assembly/index'; -import { Address, BigInt } from '@graphprotocol/graph-ts'; -import { Approval } from '../generated/schema'; -import { Approval as ApprovalEvent } from '../generated/FleekNFA/FleekNFA'; -import { handleApproval } from '../src/fleek-nfa'; -import { createApprovalEvent } from './fleek-nfa-utils'; - -// Tests structure (matchstick-as >=0.5.0) -// https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0 +import { BigInt, Bytes } from '@graphprotocol/graph-ts'; +import '../generated/schema'; +import '../generated/FleekNFA/FleekNFA'; +import '../src/fleek-nfa'; +import './utils'; +import { + NewBuild, + NewTokenDescription, + NewTokenENS, + NewTokenExternalURL, + NewTokenName, + Transfer, +} from '../generated/FleekNFA/FleekNFA'; +import { + CONTRACT, + createNewBuildEvent, + createNewTokenDescriptionEvent, + createNewTokenENSEvent, + createNewTokenExternalURLEvent, + createNewTokenNameEvent, + createTransferEvent, + handleNewBuilds, + handleNewTokenDescriptions, + handleNewTokenENSAddresses, + handleNewTokenExternalURLs, + handleNewTokenNames, + handleTransfers, + makeEventId, + TOKEN_OWNER_ONE, + TOKEN_OWNER_TWO, +} from './utils'; describe('Describe entity assertions', () => { beforeAll(() => { - let owner = Address.fromString( - '0x0000000000000000000000000000000000000001' + // TRANSFERS + let transfers: Transfer[] = []; + transfers.push( + createTransferEvent(0, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(0)) ); - let approved = Address.fromString( - '0x0000000000000000000000000000000000000001' + transfers.push( + createTransferEvent(1, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(1)) ); - let tokenId = BigInt.fromI32(234); - let newApprovalEvent = createApprovalEvent(owner, approved, tokenId); - handleApproval(newApprovalEvent); + transfers.push( + createTransferEvent(2, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(2)) + ); + transfers.push( + createTransferEvent(3, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(3)) + ); + transfers.push( + createTransferEvent( + 4, + TOKEN_OWNER_TWO, + TOKEN_OWNER_ONE, + BigInt.fromI32(1) + ) + ); + transfers.push( + createTransferEvent(5, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(4)) + ); + transfers.push( + createTransferEvent( + 6, + TOKEN_OWNER_ONE, + TOKEN_OWNER_TWO, + BigInt.fromI32(0) + ) + ); + handleTransfers(transfers); + + // NEW TOKEN NAME EVENTS + let newTokenNames: NewTokenName[] = []; + newTokenNames.push( + createNewTokenNameEvent( + 0, + BigInt.fromI32(0), + 'Token Zero New Name', + TOKEN_OWNER_ONE + ) + ); + newTokenNames.push( + createNewTokenNameEvent( + 1, + BigInt.fromI32(1), + 'Token One New Name', + TOKEN_OWNER_TWO + ) + ); + newTokenNames.push( + createNewTokenNameEvent( + 2, + BigInt.fromI32(2), + 'Token Two New Name', + TOKEN_OWNER_ONE + ) + ); + newTokenNames.push( + createNewTokenNameEvent( + 3, + BigInt.fromI32(3), + 'Token Three New Name', + TOKEN_OWNER_ONE + ) + ); + newTokenNames.push( + createNewTokenNameEvent( + 4, + BigInt.fromI32(4), + 'Token Four New Name', + TOKEN_OWNER_TWO + ) + ); + newTokenNames.push( + createNewTokenNameEvent( + 5, + BigInt.fromI32(0), + 'Token Zero New Name By New Owner', + TOKEN_OWNER_TWO + ) + ); + handleNewTokenNames(newTokenNames); + + // New Token ENS Addresses + let newENSAddresses: NewTokenENS[] = []; + newENSAddresses.push( + createNewTokenENSEvent( + 0, + BigInt.fromI32(0), + 'New_Token_Zero_ENS', + TOKEN_OWNER_ONE + ) + ); + newENSAddresses.push( + createNewTokenENSEvent( + 1, + BigInt.fromI32(1), + 'New_Token_One_ENS', + TOKEN_OWNER_TWO + ) + ); + newENSAddresses.push( + createNewTokenENSEvent( + 2, + BigInt.fromI32(2), + 'New_Token_Two_ENS', + TOKEN_OWNER_ONE + ) + ); + newENSAddresses.push( + createNewTokenENSEvent( + 3, + BigInt.fromI32(3), + 'New_Token_Three_ENS', + TOKEN_OWNER_ONE + ) + ); + newENSAddresses.push( + createNewTokenENSEvent( + 4, + BigInt.fromI32(4), + 'New_Token_Four_ENS', + TOKEN_OWNER_TWO + ) + ); + newENSAddresses.push( + createNewTokenENSEvent( + 5, + BigInt.fromI32(5), + 'New_Token_Five_ENS', + TOKEN_OWNER_TWO + ) + ); + handleNewTokenENSAddresses(newENSAddresses); + + // New Token Descriptions + let newTokenDescriptions: NewTokenDescription[] = []; + newTokenDescriptions.push( + createNewTokenDescriptionEvent( + 0, + BigInt.fromI32(0), + 'New Token Zero Description', + TOKEN_OWNER_ONE + ) + ); + newTokenDescriptions.push( + createNewTokenDescriptionEvent( + 1, + BigInt.fromI32(1), + 'New Token One Description', + TOKEN_OWNER_TWO + ) + ); + newTokenDescriptions.push( + createNewTokenDescriptionEvent( + 2, + BigInt.fromI32(2), + 'New Token Two Description', + TOKEN_OWNER_ONE + ) + ); + newTokenDescriptions.push( + createNewTokenDescriptionEvent( + 3, + BigInt.fromI32(3), + 'New Token Three Description', + TOKEN_OWNER_ONE + ) + ); + newTokenDescriptions.push( + createNewTokenDescriptionEvent( + 4, + BigInt.fromI32(4), + 'New Token Four Description', + TOKEN_OWNER_TWO + ) + ); + newTokenDescriptions.push( + createNewTokenDescriptionEvent( + 5, + BigInt.fromI32(5), + 'New Token Five Description By New Owner', + TOKEN_OWNER_TWO + ) + ); + handleNewTokenDescriptions(newTokenDescriptions); + + // New Token External URLs + let newTokenExternalURLs: NewTokenExternalURL[] = []; + newTokenExternalURLs.push( + createNewTokenExternalURLEvent( + 0, + BigInt.fromI32(0), + 'https://0_external.url', + TOKEN_OWNER_ONE + ) + ); + newTokenExternalURLs.push( + createNewTokenExternalURLEvent( + 1, + BigInt.fromI32(1), + 'https://1_external.url', + TOKEN_OWNER_TWO + ) + ); + newTokenExternalURLs.push( + createNewTokenExternalURLEvent( + 2, + BigInt.fromI32(2), + 'https://2_external.url', + TOKEN_OWNER_ONE + ) + ); + newTokenExternalURLs.push( + createNewTokenExternalURLEvent( + 3, + BigInt.fromI32(3), + 'https://3_external.url', + TOKEN_OWNER_ONE + ) + ); + newTokenExternalURLs.push( + createNewTokenExternalURLEvent( + 4, + BigInt.fromI32(4), + 'https://4_external.url', + TOKEN_OWNER_TWO + ) + ); + newTokenExternalURLs.push( + createNewTokenExternalURLEvent( + 5, + BigInt.fromI32(5), + 'https://5_external.url', + TOKEN_OWNER_TWO + ) + ); + handleNewTokenExternalURLs(newTokenExternalURLs); + + // New Token External URLs + let newBuilds: NewBuild[] = []; + newBuilds.push( + createNewBuildEvent(0, BigInt.fromI32(0), 'hash0_0', TOKEN_OWNER_ONE) + ); + newBuilds.push( + createNewBuildEvent(1, BigInt.fromI32(1), 'hash1_0', TOKEN_OWNER_TWO) + ); + newBuilds.push( + createNewBuildEvent(2, BigInt.fromI32(2), 'hash2_0', TOKEN_OWNER_ONE) + ); + newBuilds.push( + createNewBuildEvent(3, BigInt.fromI32(3), 'hash3_0', TOKEN_OWNER_ONE) + ); + newBuilds.push( + createNewBuildEvent(4, BigInt.fromI32(4), 'hash4_0', TOKEN_OWNER_TWO) + ); + newBuilds.push( + createNewBuildEvent(5, BigInt.fromI32(5), 'hash5_0', TOKEN_OWNER_TWO) + ); + handleNewBuilds(newBuilds); + + logStore(); }); afterAll(() => { clearStore(); }); - // For more test scenarios, see: - // https://thegraph.com/docs/en/developer/matchstick/#write-a-unit-test + describe('Transfers', () => { + test('Check the number of transfers to be valid', () => { + assert.entityCount('Transfer', 7); + }); + test('Check the `from` and `to` fields of each transfer to be equal to expected values', () => { + assert.fieldEquals( + 'Transfer', + makeEventId(0), + 'to', + '0x2000000000000000000000000000000000000002' + ); + assert.fieldEquals( + 'Transfer', + makeEventId(1), + 'to', + '0x3000000000000000000000000000000000000003' + ); + assert.fieldEquals( + 'Transfer', + makeEventId(2), + 'to', + '0x2000000000000000000000000000000000000002' + ); + assert.fieldEquals( + 'Transfer', + makeEventId(3), + 'to', + '0x2000000000000000000000000000000000000002' + ); + assert.fieldEquals( + 'Transfer', + makeEventId(4), + 'to', + '0x2000000000000000000000000000000000000002' + ); + assert.fieldEquals( + 'Transfer', + makeEventId(5), + 'to', + '0x3000000000000000000000000000000000000003' + ); + assert.fieldEquals( + 'Transfer', + makeEventId(6), + 'to', + '0x3000000000000000000000000000000000000003' + ); + }); + }); - test('Approval created and stored', () => { - assert.entityCount('Approval', 1); + describe('New Token Name Events', () => { + test('Check the number of NewTokenName to be valid', () => { + assert.entityCount('NewTokenName', 6); + }); + test('Check the `name` and `triggeredBy` fields of each new token name event to be equal to expected values', () => { + assert.fieldEquals( + 'NewTokenName', + makeEventId(0), + 'name', + 'Token Zero New Name' + ); + assert.fieldEquals( + 'NewTokenName', + makeEventId(1), + 'name', + 'Token One New Name' + ); + assert.fieldEquals( + 'NewTokenName', + makeEventId(2), + 'name', + 'Token Two New Name' + ); + assert.fieldEquals( + 'NewTokenName', + makeEventId(3), + 'name', + 'Token Three New Name' + ); + assert.fieldEquals( + 'NewTokenName', + makeEventId(4), + 'name', + 'Token Four New Name' + ); + assert.fieldEquals( + 'NewTokenName', + makeEventId(5), + 'name', + 'Token Zero New Name By New Owner' + ); + }); + }); - // 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function - assert.fieldEquals( - 'Approval', - '0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1', - 'owner', - '0x0000000000000000000000000000000000000001' - ); - assert.fieldEquals( - 'Approval', - '0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1', - 'approved', - '0x0000000000000000000000000000000000000001' - ); - assert.fieldEquals( - 'Approval', - '0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1', - 'tokenId', - '234' - ); + describe('New Token External URL Events', () => { + test('Check the number of newTokenExternalURl events to be valid', () => { + assert.entityCount('NewTokenExternalURL', 6); + }); + test('Check the `description` and `triggeredBy` fields of each new token name event to be equal to expected values', () => { + assert.fieldEquals( + 'NewTokenExternalURL', + makeEventId(0), + 'externalURL', + 'https://0_external.url' + ); + assert.fieldEquals( + 'NewTokenExternalURL', + makeEventId(1), + 'externalURL', + 'https://1_external.url' + ); + assert.fieldEquals( + 'NewTokenExternalURL', + makeEventId(2), + 'externalURL', + 'https://2_external.url' + ); + assert.fieldEquals( + 'NewTokenExternalURL', + makeEventId(3), + 'externalURL', + 'https://3_external.url' + ); + assert.fieldEquals( + 'NewTokenExternalURL', + makeEventId(4), + 'externalURL', + 'https://4_external.url' + ); + assert.fieldEquals( + 'NewTokenExternalURL', + makeEventId(5), + 'externalURL', + 'https://5_external.url' + ); + }); + }); - // More assert options: - // https://thegraph.com/docs/en/developer/matchstick/#asserts + describe('New Token Description Events', () => { + test('Check the number of NewTokenDescription events to be valid', () => { + assert.entityCount('NewTokenDescription', 6); + }); + test('Check the `description` and `triggeredBy` fields of each new token name event to be equal to expected values', () => { + assert.fieldEquals( + 'NewTokenDescription', + makeEventId(0), + 'description', + 'New Token Zero Description' + ); + assert.fieldEquals( + 'NewTokenDescription', + makeEventId(1), + 'description', + 'New Token One Description' + ); + assert.fieldEquals( + 'NewTokenDescription', + makeEventId(2), + 'description', + 'New Token Two Description' + ); + assert.fieldEquals( + 'NewTokenDescription', + makeEventId(3), + 'description', + 'New Token Three Description' + ); + assert.fieldEquals( + 'NewTokenDescription', + makeEventId(4), + 'description', + 'New Token Four Description' + ); + assert.fieldEquals( + 'NewTokenDescription', + makeEventId(5), + 'description', + 'New Token Five Description By New Owner' + ); + }); }); }); diff --git a/subgraph/tests/fleek-nfa-utils.ts b/subgraph/tests/utils.ts similarity index 55% rename from subgraph/tests/fleek-nfa-utils.ts rename to subgraph/tests/utils.ts index 525930b..19befc3 100644 --- a/subgraph/tests/fleek-nfa-utils.ts +++ b/subgraph/tests/utils.ts @@ -1,27 +1,43 @@ import { newMockEvent } from 'matchstick-as'; -import { ethereum, Address, BigInt } from '@graphprotocol/graph-ts'; +import { ethereum, Address, BigInt, Bytes } from '@graphprotocol/graph-ts'; import { - Approval, - ApprovalForAll, - CollectionRoleGranted, - CollectionRoleRevoked, - NewBuild, - NewTokenDescription, - NewTokenENS, - NewTokenExternalURL, - NewTokenImage, - NewTokenName, - TokenRoleGranted, - TokenRoleRevoked, - Transfer, + Approval as ApprovalEvent, + ApprovalForAll as ApprovalForAllEvent, + CollectionRoleGranted as CollectionRoleGrantedEvent, + CollectionRoleRevoked as CollectionRoleRevokedEvent, + NewBuild as NewBuildEvent, + NewTokenDescription as NewTokenDescriptionEvent, + NewTokenENS as NewTokenENSEvent, + NewTokenExternalURL as NewTokenExternalURLEvent, + NewTokenLogo as NewTokenLogoEvent, + NewTokenName as NewTokenNameEvent, + TokenRoleGranted as TokenRoleGrantedEvent, + TokenRoleRevoked as TokenRoleRevokedEvent, + Transfer as TransferEvent, } from '../generated/FleekNFA/FleekNFA'; +import { + handleApproval, + handleApprovalForAll, + handleCollectionRoleGranted, + handleCollectionRoleRevoked, + handleNewBuild, + handleNewTokenDescription, + handleNewTokenENS, + handleNewTokenExternalURL, + handleNewTokenLogo, + handleNewTokenName, + handleTokenRoleGranted, + handleTokenRoleRevoked, + handleTransfer, +} from '../src/fleek-nfa'; export function createApprovalEvent( + event_count: i32, owner: Address, approved: Address, tokenId: BigInt -): Approval { - let approvalEvent = changetype(newMockEvent()); +): ApprovalEvent { + let approvalEvent = changetype(newMockEvent()); approvalEvent.parameters = new Array(); @@ -38,15 +54,19 @@ export function createApprovalEvent( ) ); + approvalEvent.transaction.hash = Bytes.fromI32(event_count); + approvalEvent.logIndex = new BigInt(event_count); + return approvalEvent; } export function createApprovalForAllEvent( + event_count: i32, owner: Address, operator: Address, approved: boolean -): ApprovalForAll { - let approvalForAllEvent = changetype(newMockEvent()); +): ApprovalForAllEvent { + let approvalForAllEvent = changetype(newMockEvent()); approvalForAllEvent.parameters = new Array(); @@ -60,15 +80,19 @@ export function createApprovalForAllEvent( new ethereum.EventParam('approved', ethereum.Value.fromBoolean(approved)) ); + approvalForAllEvent.transaction.hash = Bytes.fromI32(event_count); + approvalForAllEvent.logIndex = new BigInt(event_count); + return approvalForAllEvent; } export function createCollectionRoleGrantedEvent( + event_count: i32, role: i32, toAddress: Address, byAddress: Address -): CollectionRoleGranted { - let collectionRoleGrantedEvent = changetype( +): CollectionRoleGrantedEvent { + let collectionRoleGrantedEvent = changetype( newMockEvent() ); @@ -87,15 +111,19 @@ export function createCollectionRoleGrantedEvent( new ethereum.EventParam('byAddress', ethereum.Value.fromAddress(byAddress)) ); + collectionRoleGrantedEvent.transaction.hash = Bytes.fromI32(event_count); + collectionRoleGrantedEvent.logIndex = new BigInt(event_count); + return collectionRoleGrantedEvent; } export function createCollectionRoleRevokedEvent( + event_count: i32, role: i32, toAddress: Address, byAddress: Address -): CollectionRoleRevoked { - let collectionRoleRevokedEvent = changetype( +): CollectionRoleRevokedEvent { + let collectionRoleRevokedEvent = changetype( newMockEvent() ); @@ -114,15 +142,19 @@ export function createCollectionRoleRevokedEvent( new ethereum.EventParam('byAddress', ethereum.Value.fromAddress(byAddress)) ); + collectionRoleRevokedEvent.transaction.hash = Bytes.fromI32(event_count); + collectionRoleRevokedEvent.logIndex = new BigInt(event_count); + return collectionRoleRevokedEvent; } export function createNewBuildEvent( + event_count: i32, token: BigInt, commitHash: string, triggeredBy: Address -): NewBuild { - let newBuildEvent = changetype(newMockEvent()); +): NewBuildEvent { + let newBuildEvent = changetype(newMockEvent()); newBuildEvent.parameters = new Array(); @@ -139,15 +171,19 @@ export function createNewBuildEvent( ) ); + newBuildEvent.transaction.hash = Bytes.fromI32(event_count); + newBuildEvent.logIndex = new BigInt(event_count); + return newBuildEvent; } export function createNewTokenDescriptionEvent( + event_count: i32, token: BigInt, description: string, triggeredBy: Address -): NewTokenDescription { - let newTokenDescriptionEvent = changetype( +): NewTokenDescriptionEvent { + let newTokenDescriptionEvent = changetype( newMockEvent() ); @@ -169,15 +205,19 @@ export function createNewTokenDescriptionEvent( ) ); + newTokenDescriptionEvent.transaction.hash = Bytes.fromI32(event_count); + newTokenDescriptionEvent.logIndex = new BigInt(event_count); + return newTokenDescriptionEvent; } export function createNewTokenENSEvent( + event_count: i32, token: BigInt, ENS: string, triggeredBy: Address -): NewTokenENS { - let newTokenEnsEvent = changetype(newMockEvent()); +): NewTokenENSEvent { + let newTokenEnsEvent = changetype(newMockEvent()); newTokenEnsEvent.parameters = new Array(); @@ -194,15 +234,19 @@ export function createNewTokenENSEvent( ) ); + newTokenEnsEvent.transaction.hash = Bytes.fromI32(event_count); + newTokenEnsEvent.logIndex = new BigInt(event_count); + return newTokenEnsEvent; } export function createNewTokenExternalURLEvent( + event_count: i32, token: BigInt, externalURL: string, triggeredBy: Address -): NewTokenExternalURL { - let newTokenExternalUrlEvent = changetype( +): NewTokenExternalURLEvent { + let newTokenExternalUrlEvent = changetype( newMockEvent() ); @@ -224,15 +268,19 @@ export function createNewTokenExternalURLEvent( ) ); + newTokenExternalUrlEvent.transaction.hash = Bytes.fromI32(event_count); + newTokenExternalUrlEvent.logIndex = new BigInt(event_count); + return newTokenExternalUrlEvent; } export function createNewTokenImageEvent( + event_count: i32, token: BigInt, image: string, triggeredBy: Address -): NewTokenImage { - let newTokenImageEvent = changetype(newMockEvent()); +): NewTokenImageEvent { + let newTokenImageEvent = changetype(newMockEvent()); newTokenImageEvent.parameters = new Array(); @@ -249,15 +297,19 @@ export function createNewTokenImageEvent( ) ); + newTokenImageEvent.transaction.hash = Bytes.fromI32(event_count); + newTokenImageEvent.logIndex = new BigInt(event_count); + return newTokenImageEvent; } export function createNewTokenNameEvent( + event_count: i32, token: BigInt, name: string, triggeredBy: Address -): NewTokenName { - let newTokenNameEvent = changetype(newMockEvent()); +): NewTokenNameEvent { + let newTokenNameEvent = changetype(newMockEvent()); newTokenNameEvent.parameters = new Array(); @@ -274,16 +326,20 @@ export function createNewTokenNameEvent( ) ); + newTokenNameEvent.transaction.hash = Bytes.fromI32(event_count); + newTokenNameEvent.logIndex = new BigInt(event_count); + return newTokenNameEvent; } export function createTokenRoleGrantedEvent( + event_count: i32, tokenId: BigInt, role: i32, toAddress: Address, byAddress: Address -): TokenRoleGranted { - let tokenRoleGrantedEvent = changetype(newMockEvent()); +): TokenRoleGrantedEvent { + let tokenRoleGrantedEvent = changetype(newMockEvent()); tokenRoleGrantedEvent.parameters = new Array(); @@ -306,16 +362,20 @@ export function createTokenRoleGrantedEvent( new ethereum.EventParam('byAddress', ethereum.Value.fromAddress(byAddress)) ); + tokenRoleGrantedEvent.transaction.hash = Bytes.fromI32(event_count); + tokenRoleGrantedEvent.logIndex = new BigInt(event_count); + return tokenRoleGrantedEvent; } export function createTokenRoleRevokedEvent( + event_count: i32, tokenId: BigInt, role: i32, toAddress: Address, byAddress: Address -): TokenRoleRevoked { - let tokenRoleRevokedEvent = changetype(newMockEvent()); +): TokenRoleRevokedEvent { + let tokenRoleRevokedEvent = changetype(newMockEvent()); tokenRoleRevokedEvent.parameters = new Array(); @@ -338,15 +398,19 @@ export function createTokenRoleRevokedEvent( new ethereum.EventParam('byAddress', ethereum.Value.fromAddress(byAddress)) ); + tokenRoleRevokedEvent.transaction.hash = Bytes.fromI32(event_count); + tokenRoleRevokedEvent.logIndex = new BigInt(event_count); + return tokenRoleRevokedEvent; } export function createTransferEvent( + event_count: i32, from: Address, to: Address, tokenId: BigInt -): Transfer { - let transferEvent = changetype(newMockEvent()); +): TransferEvent { + let transferEvent = changetype(newMockEvent()); transferEvent.parameters = new Array(); @@ -363,5 +427,111 @@ export function createTransferEvent( ) ); + transferEvent.transaction.hash = Bytes.fromI32(event_count); + transferEvent.logIndex = new BigInt(event_count); + return transferEvent; } + +export const CONTRACT: Address = Address.fromString( + '0x0000000000000000000000000000000000000000' +); +export const CONTRACT_OWNER: Address = Address.fromString( + '0x1000000000000000000000000000000000000001' +); +export const TOKEN_OWNER_ONE: Address = Address.fromString( + '0x2000000000000000000000000000000000000002' +); +export const TOKEN_OWNER_TWO: Address = Address.fromString( + '0x3000000000000000000000000000000000000003' +); + +export function handleTransfers(events: TransferEvent[]): void { + events.forEach((event) => { + handleTransfer(event); + }); +} + +export function handleNewTokenNames(events: NewTokenNameEvent[]): void { + events.forEach((event) => { + handleNewTokenName(event); + }); +} + +export function handleNewTokenDescriptions( + events: NewTokenDescriptionEvent[] +): void { + events.forEach((event) => { + handleNewTokenDescription(event); + }); +} + +export function handleNewTokenENSAddresses(events: NewTokenENSEvent[]): void { + events.forEach((event) => { + handleNewTokenENS(event); + }); +} + +export function handleNewTokenExternalURLs( + events: NewTokenExternalURLEvent[] +): void { + events.forEach((event) => { + handleNewTokenExternalURL(event); + }); +} + +export function handleNewBuilds(events: NewBuildEvent[]): void { + events.forEach((event) => { + handleNewBuild(event); + }); +} + +export function handleNewTokenLogos(events: NewTokenLogoEvent[]): void { + events.forEach((event) => { + handleNewTokenLogo(event); + }); +} + +export function handleApprovals(events: ApprovalEvent[]): void { + events.forEach((event) => { + handleApproval(event); + }); +} + +export function handleApprovalForAlls(events: ApprovalForAllEvent[]): void { + events.forEach((event) => { + handleApprovalForAll(event); + }); +} + +export function handleCollectionRoleGranteds( + events: CollectionRoleGrantedEvent[] +): void { + events.forEach((event) => { + handleCollectionRoleGranted(event); + }); +} + +export function handleCollectionRoleRevokeds( + events: CollectionRoleRevokedEvent[] +): void { + events.forEach((event) => { + handleCollectionRoleRevoked(event); + }); +} + +export function handleTokenRoleGranteds(events: TokenRoleGrantedEvent[]): void { + events.forEach((event) => { + handleTokenRoleGranted(event); + }); +} + +export function handleTokenRoleRevokeds(events: TokenRoleRevokedEvent[]): void { + events.forEach((event) => { + handleTokenRoleRevoked(event); + }); +} + +export function makeEventId(id: i32): string { + return Bytes.fromI32(id).toHexString() + '00000000'; +} diff --git a/subgraph/yarn.lock b/subgraph/yarn.lock index 121c816..b0f6dd6 100644 --- a/subgraph/yarn.lock +++ b/subgraph/yarn.lock @@ -1445,9 +1445,9 @@ glob@^7.1.3: once "^1.3.0" path-is-absolute "^1.0.0" -"gluegun@git+https://github.com/edgeandnode/gluegun.git#v4.3.1-pin-colors-dep": +"gluegun@https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep": version "4.3.1" - resolved "git+https://github.com/edgeandnode/gluegun.git#b34b9003d7bf556836da41b57ef36eb21570620a" + resolved "https://github.com/edgeandnode/gluegun#b34b9003d7bf556836da41b57ef36eb21570620a" dependencies: apisauce "^1.0.1" app-module-path "^2.2.0"