Skip to content

Commit

Permalink
new: attempting to check with mapping for ERC721 tokens in Registry c…
Browse files Browse the repository at this point in the history
…ontract, in runtime, when plasma token mapped event is received
  • Loading branch information
itzmeanjan committed Jan 27, 2021
1 parent 89fa36a commit 72fab40
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions root/src/mappings/registry.ts
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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
Expand Down

0 comments on commit 72fab40

Please sign in to comment.