1
- import { BeefyERC20Product as BeefyERC20ProductTemplate } from "../../../generated/templates"
1
+ import {
2
+ BeefyERC20Product as BeefyERC20ProductTemplate ,
3
+ ContractDeployerInitializable as ContractDeployerInitializableTemplate ,
4
+ } from "../../../generated/templates"
2
5
import { ContractDeployed as ContractDeployedEvent } from "../../../generated/ContractDeployer/ContractDeployer"
3
6
import { IERC20 as IERC20Contract } from "../../../generated/templates/BeefyERC20Product/IERC20"
4
7
import { fetchAndSaveTokenData } from "../utils/token"
@@ -9,27 +12,30 @@ export function handleContractDeployedWithDeployer(event: ContractDeployedEvent)
9
12
10
13
// detect if we are creating an erc20 token
11
14
const tokenContract = IERC20Contract . bind ( Address . fromBytes ( address ) )
12
-
13
15
const tokenDecimalsRes = tokenContract . try_decimals ( )
14
16
if ( tokenDecimalsRes . reverted ) {
15
17
log . info ( "Contract {} is not an ERC20 token, decimals() reverted" , [ address . toHexString ( ) ] )
16
18
return
17
19
}
18
-
19
20
const tokenNameRes = tokenContract . try_name ( )
20
21
if ( tokenNameRes . reverted ) {
21
22
log . info ( "Contract {} is not an ERC20 token, name() reverted" , [ address . toHexString ( ) ] )
22
23
return
23
24
}
24
-
25
25
const tokenSymbolRes = tokenContract . try_symbol ( )
26
26
if ( tokenSymbolRes . reverted ) {
27
27
log . info ( "Contract {} is not an ERC20 token, symbol() reverted" , [ address . toHexString ( ) ] )
28
28
return
29
29
}
30
30
31
- log . debug ( "Creating BeefyERC20Product template for {} from contract-deployer" , [ address . toHexString ( ) ] )
31
+ // if any of the calls return null, this is most likely an initializable contract
32
+ if ( tokenDecimalsRes . value == null || tokenNameRes . value == null || tokenSymbolRes . value == null ) {
33
+ log . info ( "Contract {} is probably innitializable, one of the metadata calls returned null" , [ address . toHexString ( ) ] )
32
34
33
- fetchAndSaveTokenData ( address )
34
- BeefyERC20ProductTemplate . create ( address )
35
+ ContractDeployerInitializableTemplate . create ( address )
36
+ } else {
37
+ log . debug ( "Creating BeefyERC20Product template for {} from contract-deployer" , [ address . toHexString ( ) ] )
38
+ fetchAndSaveTokenData ( address )
39
+ BeefyERC20ProductTemplate . create ( address )
40
+ }
35
41
}
0 commit comments