import type { Abi, ContractFunctionArgs, ContractFunctionName, GetValue, Hex, } from 'viem' import type { TypedResponse } from './response.js' import type { UnionWiden, Widen } from './utils.js' ////////////////////////////////////////////////////// // Raw Transaction export type ChainNamespace = 'eip155' /** * Current supported chain IDs: * - 10: Optimism * - 8453: Base * - 7777777: Zora */ export type ChainIdEip155 = 10 | 8453 | 7777777 export type TransactionParameters = { /** A CAIP-2 Chain ID to identify the transaction network. */ chainId: `${ChainNamespace}:${ChainIdEip155}` } & EthSendTransactionSchema export type TransactionResponse = Pick & EthSendTransactionSchema export type EthSendTransactionSchema = { /** A method ID to identify the type of transaction request. */ method: 'eth_sendTransaction' /** Transaction calldata. */ params: EthSendTransactionParameters } export type EthSendTransactionParameters = { /** Contract ABI. */ abi?: Abi | undefined /** Transaction calldata. */ data?: Hex | undefined /** Transaction target address. */ to: Hex /** Value to send with transaction (in wei). */ value?: quantity } export type TransactionResponseFn = ( parameters: parameters, ) => TypedResponse ////////////////////////////////////////////////////// // Send Transaction export type SendTransactionParameters = Pick & EthSendTransactionParameters ////////////////////////////////////////////////////// // Contract Transaction export type ContractTransactionParameters< abi extends Abi | readonly unknown[] = Abi, functionName extends ContractFunctionName< abi, 'nonpayable' | 'payable' > = ContractFunctionName, args extends ContractFunctionArgs< abi, 'nonpayable' | 'payable', functionName > = ContractFunctionArgs, /// allFunctionNames = ContractFunctionName, allArgs = ContractFunctionArgs, > = Pick & { /** Contract ABI. */ abi: abi /** Contract function arguments. */ args?: (abi extends Abi ? UnionWiden : never) | allArgs | undefined /** Contract function name to invoke. */ functionName: | allFunctionNames // show all options | (functionName extends allFunctionNames ? functionName : never) // infer value } & (readonly [] extends allArgs ? {} : { args: Widen }) & GetValue export type ContractTransactionResponseFn = < const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName, args extends ContractFunctionArgs< abi, 'nonpayable' | 'payable', functionName >, >( response: ContractTransactionParameters, ) => TypedResponse