@@ -113,80 +113,54 @@ const constructParams = (chain: SupportedChains) => {
113113 return async ( fromBlock : number , toBlock : number ) => {
114114 const eventLogData = await getTxDataFromEVMEventLogs ( "retrobridge" , chain as Chain , fromBlock , toBlock , eventParams ) ;
115115
116- const nativeEvents = await Promise . all ( [
117- ...bridgeAddress . map ( async ( address : string , i : number ) => {
118- await wait ( 300 * i ) ; // for etherscan
119- let txs : any [ ] = [ ] ;
120- if ( chain === "merlin" ) {
121- txs = await getTxsBlockRangeMerlinScan ( address , fromBlock , toBlock , {
122- includeSignatures : [ "0x" ] ,
123- } ) ;
124- } else if ( chain === "btr" ) {
125- txs = await getTxsBlockRangeBtrScan ( address , fromBlock , toBlock , {
126- includeSignatures : [ "0x" ] ,
127- } ) ;
128- } else {
129- txs = await getTxsBlockRangeEtherscan ( chain , address , fromBlock , toBlock , {
130- includeSignatures : [ "0x" ] ,
131- } ) ;
132- }
133- const eventsRes : EventData [ ] = txs . map ( ( tx : any ) => {
134- const event : EventData = {
135- txHash : tx . hash ,
136- blockNumber : + tx . blockNumber ,
137- from : tx . from ,
138- to : tx . to ,
139- token : nativeTokens [ chain ] ,
140- amount : tx . value ,
141- isDeposit : address . toLowerCase ( ) === tx . to ,
142- } ;
143- return event ;
144- } ) ;
116+ const allAddresses = [ ...bridgeAddress , ...contractAddress ] ;
117+ const nativeEvents : EventData [ ] [ ] = [ ] ;
118+
119+ for ( let i = 0 ; i < allAddresses . length ; i ++ ) {
120+ await wait ( 500 ) ;
121+ const address = allAddresses [ i ] ;
122+ const isBridgeAddress = i < bridgeAddress . length ;
145123
146- return eventsRes ;
147- } ) ,
148- ...contractAddress . map ( async ( address : string , i : number ) => {
149- await wait ( 300 * i ) ; // for etherscan
150- let txs : any [ ] = [ ] ;
151- if ( chain === "merlin" ) {
152- txs = await getTxsBlockRangeMerlinScan ( address , fromBlock , toBlock , {
153- includeSignatures : [
154- "0x769254a71d2f67d8ac6cb44f2803c0d05cfbcf9effadb6a984f10ff9de3df6c3" ,
155- "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
156- ] ,
157- } ) ;
158- } else if ( chain === "btr" ) {
159- txs = await getTxsBlockRangeBtrScan ( address , fromBlock , toBlock , {
160- includeSignatures : [
161- "0x769254a71d2f67d8ac6cb44f2803c0d05cfbcf9effadb6a984f10ff9de3df6c3" ,
162- "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
163- ] ,
164- } ) ;
165- } else {
166- txs = await getTxsBlockRangeEtherscan ( chain , address , fromBlock , toBlock , {
167- includeSignatures : [
168- "0x769254a71d2f67d8ac6cb44f2803c0d05cfbcf9effadb6a984f10ff9de3df6c3" ,
169- "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
170- ] ,
171- } ) ;
172- }
173- const eventsRes : EventData [ ] = txs . filter ( ( tx : any ) => String ( tx . value ) != "0" ) . map ( ( tx : any ) => {
174- const event : EventData = {
175- txHash : tx . hash ,
176- blockNumber : + tx . blockNumber ,
177- from : tx . from ,
178- to : tx . to ,
179- token : nativeTokens [ chain ] ,
180- amount : ethers . BigNumber . from ( tx . value ) ,
181- isDeposit : address . toLowerCase ( ) === tx . to ,
182- } ;
183- return event ;
124+ let txs : any [ ] = [ ] ;
125+ if ( chain === "merlin" ) {
126+ txs = await getTxsBlockRangeMerlinScan ( address , fromBlock , toBlock , {
127+ includeSignatures : isBridgeAddress ? [ "0x" ] : [
128+ "0x769254a71d2f67d8ac6cb44f2803c0d05cfbcf9effadb6a984f10ff9de3df6c3" ,
129+ "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
130+ ] ,
131+ } ) ;
132+ } else if ( chain === "btr" ) {
133+ txs = await getTxsBlockRangeBtrScan ( address , fromBlock , toBlock , {
134+ includeSignatures : isBridgeAddress ? [ "0x" ] : [
135+ "0x769254a71d2f67d8ac6cb44f2803c0d05cfbcf9effadb6a984f10ff9de3df6c3" ,
136+ "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
137+ ] ,
184138 } ) ;
139+ } else {
140+ txs = await getTxsBlockRangeEtherscan ( chain , address , fromBlock , toBlock , {
141+ includeSignatures : isBridgeAddress ? [ "0x" ] : [
142+ "0x769254a71d2f67d8ac6cb44f2803c0d05cfbcf9effadb6a984f10ff9de3df6c3" ,
143+ "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
144+ ] ,
145+ } ) ;
146+ }
147+
148+ const filteredTxs = isBridgeAddress ? txs : txs . filter ( ( tx : any ) => String ( tx . value ) != "0" ) ;
149+ const eventsRes : EventData [ ] = filteredTxs . map ( ( tx : any ) => {
150+ const event : EventData = {
151+ txHash : tx . hash ,
152+ blockNumber : + tx . blockNumber ,
153+ from : tx . from ,
154+ to : tx . to ,
155+ token : nativeTokens [ chain ] ,
156+ amount : isBridgeAddress ? tx . value : ethers . BigNumber . from ( tx . value ) ,
157+ isDeposit : address . toLowerCase ( ) === tx . to ,
158+ } ;
159+ return event ;
160+ } ) ;
185161
186- return eventsRes ;
187- } )
188- ]
189- ) ;
162+ nativeEvents . push ( eventsRes ) ;
163+ }
190164 const allEvents = [ ...eventLogData , ...nativeEvents . flat ( ) ] ;
191165 return allEvents ;
192166 } ;
0 commit comments