import type { Abi, Address, ExtractAbiEvent, ExtractAbiEventNames, FormatAbi, ParseAbi, } from 'abitype' import type { BlockNumber, BlockTag, CreateEventFilterParameters, GetEventArgs, Hex, } from 'viem' /** * Adapted from viem. This is a helper type to extract the event args from an abi */ export type MaybeExtractEventArgsFromAbi< TAbi extends Abi | readonly unknown[] | undefined, TEventName extends string | undefined, > = TAbi extends Abi | readonly unknown[] ? TEventName extends string ? GetEventArgs : undefined : undefined export type ValueOf = T[keyof T] /** * A mapping of event names to action creators for events. Can be used to create event filters in a typesafe way * @example * ```typescript * tevm.eth.getLog( * MyScript.withAddress('0x420...').events.Transfer({ from: '0x1234...' }), * ) * === */ export type EventActionCreator< THumanReadableAbi extends readonly string[], TBytecode extends Hex | undefined, TDeployedBytecode extends Hex | undefined, TAddress extends Address | undefined, TAddressArgs = TAddress extends undefined ? {} : { address: TAddress }, > = { // for every event in the abi, create an action creator [TEventName in ExtractAbiEventNames>]: (< TStrict extends boolean = false, TFromBlock extends BlockNumber | BlockTag | undefined = undefined, TToBlock extends BlockNumber | BlockTag | undefined = undefined, >( // take take these actions. These match the shape of viem actions params: Pick< // CreateEventFilterParameters create viem like parameters // we are taking the subset that aren't implied already from Contract.event.eventName specification // such as abi, eventName etc. CreateEventFilterParameters< ExtractAbiEvent, TEventName>, ParseAbi, TStrict, TFromBlock, TToBlock, TEventName, MaybeExtractEventArgsFromAbi, TEventName> >, 'fromBlock' | 'toBlock' | 'args' | 'strict' >, // Return the following parameters. It merges the supplied parameters with the event name and abi etc. ) => CreateEventFilterParameters< ExtractAbiEvent, TEventName>, ParseAbi, TStrict, TFromBlock, TToBlock, TEventName, MaybeExtractEventArgsFromAbi, TEventName> > & { eventName: TEventName abi: [ExtractAbiEvent, TEventName>] bytecode: TBytecode deployedBytecode: TDeployedBytecode // if you use the action creator without supplying arguments it's the same shape but missing args // can be useful for lazily evaluating }) & { eventName: TEventName humanReadableAbi: FormatAbi< [ExtractAbiEvent, TEventName>] > abi: [ExtractAbiEvent, TEventName>] bytecode: TBytecode deployedBytecode: TDeployedBytecode } & TAddressArgs }