-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for initializable contract deployed with deployer
- Loading branch information
Showing
6 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{ | ||
"anonymous": false, | ||
"inputs": [{ "indexed": false, "internalType": "uint8", "name": "version", "type": "uint8" }], | ||
"name": "Initialized", | ||
"type": "event" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { BeefyERC20Product as BeefyERC20ProductTemplate } from "../../../generated/templates" | ||
import { Initialized as InitializedEvent } from "../../../generated/ContractDeployer/Initializable" | ||
import { IERC20 as IERC20Contract } from "../../../generated/templates/BeefyERC20Product/IERC20" | ||
import { Address, log } from "@graphprotocol/graph-ts" | ||
import { fetchAndSaveTokenData } from "../utils/token" | ||
|
||
export function handleContractDeployedInitializableInitialized(event: InitializedEvent): void { | ||
const tokenAddress = event.address | ||
|
||
// detect if we are creating an erc20 token | ||
const tokenContract = IERC20Contract.bind(Address.fromBytes(tokenAddress)) | ||
|
||
const tokenDecimalsRes = tokenContract.try_decimals() | ||
if (tokenDecimalsRes.reverted) { | ||
log.info("Contract {} is not an ERC20 token, decimals() reverted", [tokenAddress.toHexString()]) | ||
return | ||
} | ||
|
||
const tokenNameRes = tokenContract.try_name() | ||
if (tokenNameRes.reverted) { | ||
log.info("Contract {} is not an ERC20 token, name() reverted", [tokenAddress.toHexString()]) | ||
return | ||
} | ||
|
||
const tokenSymbolRes = tokenContract.try_symbol() | ||
if (tokenSymbolRes.reverted) { | ||
log.info("Contract {} is not an ERC20 token, symbol() reverted", [tokenAddress.toHexString()]) | ||
return | ||
} | ||
|
||
log.debug("Creating BeefyERC20Product template for {} from contract-deployer", [tokenAddress.toHexString()]) | ||
|
||
fetchAndSaveTokenData(tokenAddress) | ||
BeefyERC20ProductTemplate.create(tokenAddress) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters