|
1 | 1 | import { BeefyERC20Product as BeefyERC20ProductTemplate } from "../../../generated/templates"
|
2 | 2 | import { ContractDeployed as ContractDeployedEvent } from "../../../generated/ContractDeployer/ContractDeployer"
|
| 3 | +import { IERC20 as IERC20Contract } from "../../../generated/templates/BeefyERC20Product/IERC20" |
| 4 | +import { fetchAndSaveTokenData } from "../utils/token" |
| 5 | +import { Address, log } from "@graphprotocol/graph-ts" |
3 | 6 |
|
4 | 7 | export function handleContractDeployedWithDeployer(event: ContractDeployedEvent): void {
|
5 | 8 | const address = event.params.deploymentAddress
|
| 9 | + |
| 10 | + // detect if we are creating an erc20 token |
| 11 | + const tokenContract = IERC20Contract.bind(Address.fromBytes(address)) |
| 12 | + |
| 13 | + const tokenDecimalsRes = tokenContract.try_decimals() |
| 14 | + if (tokenDecimalsRes.reverted) { |
| 15 | + log.info("Contract {} is not an ERC20 token, decimals() reverted", [address.toHexString()]) |
| 16 | + return |
| 17 | + } |
| 18 | + |
| 19 | + const tokenNameRes = tokenContract.try_name() |
| 20 | + if (tokenNameRes.reverted) { |
| 21 | + log.info("Contract {} is not an ERC20 token, name() reverted", [address.toHexString()]) |
| 22 | + return |
| 23 | + } |
| 24 | + |
| 25 | + const tokenSymbolRes = tokenContract.try_symbol() |
| 26 | + if (tokenSymbolRes.reverted) { |
| 27 | + log.info("Contract {} is not an ERC20 token, symbol() reverted", [address.toHexString()]) |
| 28 | + return |
| 29 | + } |
| 30 | + |
| 31 | + log.debug("Creating BeefyERC20Product template for {} from contract-deployer", [address.toHexString()]) |
| 32 | + |
| 33 | + fetchAndSaveTokenData(address) |
6 | 34 | BeefyERC20ProductTemplate.create(address)
|
7 | 35 | }
|
0 commit comments