44 confirmOperation ,
55 callReadMethodSilent ,
66} from 'utils' ;
7- import { Address , Hex , stringToHex , zeroHash } from 'viem' ;
7+ import { Address , Hex , stringToHex , zeroHash , isHash } from 'viem' ;
88import { getTimeLockContract } from 'contracts/defi-wrapper/index.js' ;
99import { getPublicClient } from 'providers' ;
1010
@@ -23,23 +23,21 @@ export const resolveRole = async (
2323 contractAddress : Address ,
2424 getContract : ( address : Address ) => Promise < any > ,
2525) : Promise < Hex > => {
26- if ( ! roleInput . startsWith ( '0x' ) ) {
27- const contract = await getContract ( contractAddress ) ;
28- try {
29- const role = ( await callReadMethodSilent ( {
30- contract,
31- methodName : roleInput as any ,
32- payload : [ ] ,
33- } ) ) as Hex ;
34- logInfo ( `Resolved role "${ roleInput } " to ${ role } ` ) ;
35- return role ;
36- } catch {
37- throw new Error (
38- `Failed to resolve role "${ roleInput } ". Please provide a valid role name (e.g., DEFAULT_ADMIN_ROLE) or bytes32 hex.` ,
39- ) ;
40- }
41- } else {
42- return roleInput as Hex ;
26+ if ( isHash ( roleInput ) ) return roleInput ;
27+
28+ const contract = await getContract ( contractAddress ) ;
29+ try {
30+ const role = ( await callReadMethodSilent ( {
31+ contract,
32+ methodName : roleInput as any ,
33+ payload : [ ] ,
34+ } ) ) as Hex ;
35+ logInfo ( `Resolved role "${ roleInput } " to ${ role } ` ) ;
36+ return role ;
37+ } catch {
38+ throw new Error (
39+ `Failed to resolve role "${ roleInput } ". Please provide a valid role name (e.g., DEFAULT_ADMIN_ROLE) or bytes32 hex.` ,
40+ ) ;
4341 }
4442} ;
4543
0 commit comments