@@ -57,8 +57,14 @@ export type GetContractEventsResult<
5757
5858export type GetLogsParamsExtra = {
5959 signature ?: string ;
60+ insightTopicFilters ?: InsightTopicFilter [ ] ;
6061} & GetLogsParams ;
6162
63+ export type InsightTopicFilter = {
64+ topic : Hex ;
65+ index : 1 | 2 | 3 ;
66+ } ;
67+
6268/**
6369 * Retrieves events from a contract based on the provided options.
6470 * @param options - The options for retrieving events.
@@ -114,7 +120,9 @@ export async function getContractEvents<
114120 > [ ] ,
115121 const TStrict extends boolean = true ,
116122> (
117- options : GetContractEventsOptions < abi , abiEvents , TStrict > ,
123+ options : GetContractEventsOptions < abi , abiEvents , TStrict > & {
124+ insightTopicFilters ?: InsightTopicFilter [ ] ;
125+ } ,
118126) : Promise < GetContractEventsResult < abiEvents , TStrict > > {
119127 const { contract, events, blockRange, ...restParams } = options ;
120128
@@ -182,6 +190,7 @@ export async function getContractEvents<
182190 address : getAddress ( contract . address ) ,
183191 topics : e . topics ,
184192 signature : `${ e ?. abiEvent . name } (${ e ?. abiEvent . inputs . map ( ( i ) => i . type ) . join ( "," ) } )` ,
193+ insightTopicFilters : options . insightTopicFilters ,
185194 } ) )
186195 : // otherwise we want "all" events (aka not pass any topics at all)
187196 [ { ...restParams , address : getAddress ( contract . address ) } ] ;
@@ -220,8 +229,9 @@ async function getLogsFromInsight(options: {
220229 chain : Chain ;
221230 client : ThirdwebClient ;
222231 signature ?: string ;
232+ insightTopicFilters ?: InsightTopicFilter [ ] ;
223233} ) : Promise < Log [ ] > {
224- const { params, chain, client } = options ;
234+ const { params, chain, client, signature , insightTopicFilters } = options ;
225235
226236 const chainServices = await getChainServices ( chain ) ;
227237 const insightEnabled = chainServices . some (
@@ -237,8 +247,8 @@ async function getLogsFromInsight(options: {
237247 let path = "" ;
238248 if ( params . address ) {
239249 path += `/${ params . address } ` ;
240- if ( params . signature ) {
241- path += `/${ params . signature } ` ;
250+ if ( signature ) {
251+ path += `/${ signature } ` ;
242252 }
243253 }
244254 const url = new URL ( path , baseUrl ) ;
@@ -267,6 +277,15 @@ async function getLogsFromInsight(options: {
267277 }
268278 }
269279
280+ if ( insightTopicFilters ) {
281+ for ( const topicFilter of insightTopicFilters ) {
282+ url . searchParams . set (
283+ `filter_topic_${ topicFilter . index } ` ,
284+ topicFilter . topic ,
285+ ) ;
286+ }
287+ }
288+
270289 const clientFetch = getClientFetch ( client ) ;
271290 const result = await clientFetch ( url . toString ( ) ) ;
272291 const fetchedEventData = ( await result . json ( ) ) as {
0 commit comments