From 72fab40495a0995aece7d6ac029b47f67beb04c4 Mon Sep 17 00:00:00 2001 From: Anjan Roy Date: Wed, 27 Jan 2021 23:34:16 +0530 Subject: [PATCH] new: attempting to check with mapping for ERC721 tokens in Registry contract, in runtime, when plasma token mapped event is received --- root/src/mappings/registry.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/root/src/mappings/registry.ts b/root/src/mappings/registry.ts index 796643f..28dd257 100644 --- a/root/src/mappings/registry.ts +++ b/root/src/mappings/registry.ts @@ -1,6 +1,16 @@ +import { Address } from '@graphprotocol/graph-ts' + import { TokenMapped } from '../../generated/Registry/Registry' import { TokenMapping } from '../../generated/schema' +// Using contract address for creating instance of `Registry` +// contract, to be used for checking whether token is ERC20/ ERC721 +import { registryAddress } from '../network' + +// This is the contract we're going to interact with when `TokenMapped` event is emitted +// to check what kind of token it is +import { Registry } from '../../generated/Registry/Registry' + export function handlePlasmaTokenMapped(event: TokenMapped): void { let id = 'plasma-token-mapping-' + event.params.rootToken.toHexString() @@ -11,6 +21,18 @@ export function handlePlasmaTokenMapped(event: TokenMapped): void { entity.rootToken = event.params.rootToken entity.childToken = event.params.childToken + + // Attempting to check from `Registry` contract what kind of + // token it is. + // + // `tokenType` will be any of two possible values for Plasma Tokens + // + // 1. keccak256('ERC721') = 0x73ad2146b3d3a286642c794379d750360a2d53a3459a11b3e5d6cc900f55f44a + // 2. keccak256('ERC20') = 0x8ae85d849167ff996c04040c44924fd364217285e4cad818292c7ac37c0a345b + let registry = Registry.bind(Address.fromString(registryAddress)) + entity.tokenType = registry.isERC721(event.params.rootToken) ? '0x73ad2146b3d3a286642c794379d750360a2d53a3459a11b3e5d6cc900f55f44a' : '0x8ae85d849167ff996c04040c44924fd364217285e4cad818292c7ac37c0a345b' + + // Yes, this is plasma mapping handler, so it's a plasma bridge token entity.isPOS = false entity.timestamp = event.block.timestamp