vikiival / mimick

Indexer for ink! based NFTs
GNU General Public License v3.0
1 stars 3 forks source link

Factory indexing #4

Open vikiival opened 1 year ago

vikiival commented 1 year ago

EVM processor has ability to check for factory contracts

SQUID EVM FACTORY

It would be possible to use this approach and would be much simplier than #3.

Blocked by SubSquid currently

vikiival commented 1 year ago

I don't have examples related to handling ink factory contracts... but i believe it can be achived by code like this:

const FACTORY_ADDRESS = '0x5207202c27b646ceeb294ce516d4334edafbd771f869215cb070ba51dd7e2c72'

const processor = new SubstrateBatchProcessor()
    .setDataSource({
        archive: "https://shibuya.archive.subsquid.io/graphql"
    })
    .addContractsContractEmitted('*')

processor.run(new TypeormDatabase(), async (ctx) => {
    for (const block of ctx.blocks) {
        for (const item of block.items) {
            if (item.kind === 'event' && item.name === 'Contracts.ContractEmitted') {
                const contractAddress = item.event.args.contract
                if (contractAddress === FACTORY_ADDRESS) {
                    // update the list of contracts to watch
                } else if (await isPairContract(ctx.store, contractAddress)) {
                    // the contract has been created by the factory,
                    // index the event
                }
            }
        }
    }
})

ink! smart contracts have topics but they are encoded in data (item.event.args.data) so only contractAddress can be filtered

vikiival commented 1 year ago

The question for the @subsquid team.

Is it possible to add some sort of filtering?

dzhelezov commented 1 year ago

@tmcgroul can we implement something like this?

tmcgroul commented 1 year ago

unfortunately it's impossible to add additional filtering. contracts-pallet just doesn't expose enough open data for filtering (only contract address)