99 getFunctionSelector ,
1010} from 'viem' ;
1111
12- import { rollupCreatorABI as rollupCreatorV3Dot1ABI } from './contracts/RollupCreator' ;
1312import { rollupCreatorABI as rollupCreatorV2Dot1ABI } from './contracts/RollupCreator/v2.1' ;
1413import { rollupCreatorABI as rollupCreatorV1Dot1ABI } from './contracts/RollupCreator/v1.1' ;
1514import { upgradeExecutorABI } from './contracts/UpgradeExecutor' ;
@@ -20,17 +19,12 @@ import { rollupABI as rollupV2Dot1ABI } from './contracts/Rollup/v2.1';
2019import { createRollupFetchTransactionHash } from './createRollupFetchTransactionHash' ;
2120import { getLogsWithBatching } from './utils/getLogsWithBatching' ;
2221
23- const createRollupV3Dot1ABI = getAbiItem ( { abi : rollupCreatorV3Dot1ABI , name : 'createRollup' } ) ;
24- const createRollupV3Dot1FunctionSelector = getFunctionSelector ( createRollupV3Dot1ABI ) ;
25-
2622const createRollupV2Dot1ABI = getAbiItem ( { abi : rollupCreatorV2Dot1ABI , name : 'createRollup' } ) ;
2723const createRollupV2Dot1FunctionSelector = getFunctionSelector ( createRollupV2Dot1ABI ) ;
2824
2925const createRollupV1Dot1ABI = getAbiItem ( { abi : rollupCreatorV1Dot1ABI , name : 'createRollup' } ) ;
3026const createRollupV1Dot1FunctionSelector = getFunctionSelector ( createRollupV1Dot1ABI ) ;
3127
32- const setValidatorV3Dot1ABI = getAbiItem ( { abi : rollupV3Dot1ABI , name : 'setValidator' } ) ;
33-
3428const setValidatorPreV3Dot1ABI = getAbiItem ( { abi : rollupV2Dot1ABI , name : 'setValidator' } ) ;
3529const setValidatorPreV3Dot1FunctionSelector = getFunctionSelector ( setValidatorPreV3Dot1ABI ) ;
3630
@@ -49,10 +43,9 @@ const validatorsSetEventAbi = getAbiItem({ abi: rollupV3Dot1ABI, name: 'Validato
4943
5044function getValidatorsFromFunctionData <
5145 TAbi extends
52- | ( typeof createRollupV3Dot1ABI ) [ ]
5346 | ( typeof createRollupV2Dot1ABI ) [ ]
5447 | ( typeof createRollupV1Dot1ABI ) [ ]
55- | ( typeof setValidatorV3Dot1ABI ) [ ] ,
48+ | ( typeof setValidatorPreV3Dot1ABI ) [ ] ,
5649> ( { abi, data } : { abi : TAbi ; data : Hex } ) {
5750 const { args } = decodeFunctionData ( {
5851 abi,
@@ -86,7 +79,7 @@ function iterateThroughValidatorsList(
8679
8780function updateAccumulator ( acc : Set < Address > , input : Hex ) {
8881 const [ validators , enabled ] = getValidatorsFromFunctionData ( {
89- abi : [ setValidatorV3Dot1ABI ] ,
82+ abi : [ setValidatorPreV3Dot1ABI ] ,
9083 data : input ,
9184 } ) ;
9285
@@ -166,7 +159,11 @@ export async function getValidators<TChain extends Chain>(
166159 return iterateThroughValidatorsList ( acc , _validators , _enabled ) ;
167160 } , new Set < Address > ( ) ) ;
168161
169- const txs = await Promise . all (
162+ /** For pre v3.1, the OwnerFunctionCalled event is emitted when the validators list is updated
163+ * the event is emitted without the validators list and the new states in the event args
164+ * so we have to grab the tx and decode the calldata to get the validators list
165+ */
166+ const preV3Dot1Txs = await Promise . all (
170167 preV3Dot1Events . map ( ( event ) =>
171168 publicClient . getTransaction ( {
172169 hash : event . transactionHash ,
@@ -175,18 +172,10 @@ export async function getValidators<TChain extends Chain>(
175172 ) ;
176173
177174 let isAccurate = true ;
178- const validators = txs . reduce ( ( acc , tx ) => {
175+ const validators = preV3Dot1Txs . reduce ( ( acc , tx ) => {
179176 const txSelectedFunction = tx . input . slice ( 0 , 10 ) ;
180177
181178 switch ( txSelectedFunction ) {
182- case createRollupV3Dot1FunctionSelector : {
183- const [ { validators } ] = getValidatorsFromFunctionData ( {
184- abi : [ createRollupV3Dot1ABI ] ,
185- data : tx . input ,
186- } ) ;
187-
188- return new Set ( [ ...acc , ...validators ] ) ;
189- }
190179 case createRollupV2Dot1FunctionSelector : {
191180 const [ { validators } ] = getValidatorsFromFunctionData ( {
192181 abi : [ createRollupV2Dot1ABI ] ,
0 commit comments