diff --git a/src/mappings/erc721Factory.ts b/src/mappings/erc721Factory.ts index ac98438..92cc746 100644 --- a/src/mappings/erc721Factory.ts +++ b/src/mappings/erc721Factory.ts @@ -1,10 +1,15 @@ -import { NFTCreated, TokenCreated } from '../@types/ERC721Factory/ERC721Factory' +import { + NFTCreated, + TokenCreated, + ERC721Factory +} from '../@types/ERC721Factory/ERC721Factory' import { decimal } from './utils/constants' import { weiToDecimal } from './utils/generic' import { getUser } from './utils/userUtils' import { getToken, getNftToken } from './utils/tokenUtils' import { addDatatoken } from './utils/globalUtils' +import { BigInt } from '@graphprotocol/graph-ts' export function handleNftCreated(event: NFTCreated): void { // const nft = new Nft(event.params.newTokenAddress.toHexString()) @@ -42,6 +47,24 @@ export function handleNewToken(event: TokenCreated): void { token.decimals = 18 token.supply = decimal.ZERO token.cap = weiToDecimal(event.params.cap.toBigDecimal(), 18) + const eventTemplateAddress = event.params.templateAddress + .toHexString() + .toLowerCase() + const contract = ERC721Factory.bind(event.address) + const templateCount = contract.try_getCurrentTemplateCount() + if (templateCount.reverted) return + const templateCountNum = templateCount.value.toI32() + + for (let i = 0; i < templateCountNum; i++) { + const template = contract.try_getTokenTemplate(BigInt.fromI32(1 + i)) + if (template.reverted) return + const templateAddress = template.value.templateAddress + .toHexString() + .toLowerCase() + if (templateAddress == eventTemplateAddress) { + token.templateId = 1 + i + } + } token.save() addDatatoken() diff --git a/test/integration/Datatoken.test.ts b/test/integration/Datatoken.test.ts index f92c3ba..2451627 100644 --- a/test/integration/Datatoken.test.ts +++ b/test/integration/Datatoken.test.ts @@ -79,6 +79,7 @@ describe('Datatoken tests', async () => { const feeToken = '0x3210000000000000000000000000000000000000' const publishMarketFeeAmount = '0.1' const cap = '10000' + const templateIndex = 1 let datatokenAddress: string let nft: Nft let Factory: NftFactory @@ -111,13 +112,13 @@ describe('Datatoken tests', async () => { const nftParams: NftCreateData = { name: nftName, symbol: nftSymbol, - templateIndex: 1, + templateIndex, tokenURI: '', transferable: true, owner: publisher } const erc20Params: Erc20CreateParams = { - templateIndex: 1, + templateIndex, cap, feeAmount: publishMarketFeeAmount, paymentCollector: '0x0000000000000000000000000000000000000000', @@ -197,7 +198,7 @@ describe('Datatoken tests', async () => { 'incorrect value for: publishMarketFeeAmount' ) - assert(dt.templateId === null, 'incorrect value for: templateId') + assert(dt.templateId === templateIndex, 'incorrect value for: templateId') assert(dt.holderCount === '0', 'incorrect value for: holderCount') assert(dt.orderCount === '0', 'incorrect value for: orderCount') assert(dt.orders, 'incorrect value for: orders') @@ -309,7 +310,7 @@ describe('Datatoken tests', async () => { dt.publishMarketFeeAmount === publishMarketFeeAmount, 'incorrect value for: publishMarketFeeAmount' ) - assert(dt.templateId === null, 'incorrect value for: templateId') + assert(dt.templateId === templateIndex, 'incorrect value for: templateId') assert(dt.holderCount === '0', 'incorrect value for: holderCount') assert(dt.orderCount === '0', 'incorrect value for: orderCount') assert(dt.orders, 'incorrect value for: orders') @@ -337,13 +338,13 @@ describe('Datatoken tests', async () => { const nftParams: NftCreateData = { name: 'newNFT', symbol: 'newTST', - templateIndex: 1, + templateIndex, tokenURI: '', transferable: true, owner: publisher } const erc20Params: Erc20CreateParams = { - templateIndex: 1, + templateIndex, cap: '100000', feeAmount: '0', paymentCollector: ZERO_ADDRESS, diff --git a/test/integration/Nft.test.ts b/test/integration/Nft.test.ts index 726bb05..9d51204 100644 --- a/test/integration/Nft.test.ts +++ b/test/integration/Nft.test.ts @@ -24,7 +24,6 @@ const data = JSON.parse( ) const addresses = data.development -// const aquarius = new Aquarius('http://127.0.0.1:5000') const web3 = new Web3('http://127.0.0.1:8545') const providerUrl = 'http://172.15.0.4:8030'