import type { BaseContractMethod } from './BaseContractMethod.js' import type { Abi, AbiParametersToPrimitiveTypes, ExtractAbiEvent, ExtractAbiEventNames, ExtractAbiFunction, ExtractAbiFunctionNames, } from 'abitype' import type { Log } from 'ethers' import type { EventLog } from 'ethers' import type { BlockTag } from 'ethers' import type { BaseContract, ContractEventName, ContractTransactionResponse, } from 'ethers' export type TypesafeEthersContract = BaseContract & { // readonly methods [TFunctionName in ExtractAbiFunctionNames]: BaseContractMethod< AbiParametersToPrimitiveTypes< ExtractAbiFunction['inputs'] > & any[], // this is not a super robust way of doing this but should work for an initial release // this likely will have rough edges in non happy cases like the abi not being readable as const AbiParametersToPrimitiveTypes< ExtractAbiFunction['outputs'] >[0], AbiParametersToPrimitiveTypes< ExtractAbiFunction['outputs'] >[0] > } & { // write methods [TFunctionName in ExtractAbiFunctionNames< TAbi, 'nonpayable' | 'payable' >]: BaseContractMethod< AbiParametersToPrimitiveTypes< ExtractAbiFunction['inputs'] > & any[], // this is not a super robust way of doing this but should work for an initial release // this likely will have rough edges in non happy cases like the abi not being readable as const AbiParametersToPrimitiveTypes< ExtractAbiFunction['outputs'] >[0], ContractTransactionResponse > } & { // events queryFilter: < TContractEventName extends | Omit> | ExtractAbiEventNames, >( event: TContractEventName, fromBlock?: BlockTag, toBlock?: BlockTag, // TODO this return type does not work // this is extremely difficult to override the return type into being generic ) => Promise< Array< TContractEventName extends ExtractAbiEventNames ? ExtractAbiEvent : EventLog | Log > > }