import type { Abi, Address } from 'viem' import type { Compute, MaybeArray, MaybePromise } from './types.js' export type ContractConfig< chainId extends number = number, requiredChainId extends number | undefined = undefined, > = { /** * Contract ABI */ abi: Abi /** * Contract address or addresses. * * Accepts an object `{ [chainId]: address }` to support multiple chains. * * @example * '0x314159265dd8dbb310642f98f50c066173c1259b' * * @example * { * 1: '0x314159265dd8dbb310642f98f50c066173c1259b', * 5: '0x112234455c3a32fd11230c42e7bccd4a84e02010', * } */ address?: | Address | (requiredChainId extends number ? Record & Partial> : Record) | undefined /** * Name of contract. */ name: string } export type Contract = Compute< ContractConfig & { /** Generated string content */ content: string /** Meta info about contract */ meta: { abiName: string addressName?: string | undefined configName?: string | undefined } } > export type Watch = { /** Command to run along with watch process */ command?: (() => MaybePromise) | undefined /** Paths to watch for changes. */ paths: string[] | (() => MaybePromise) /** Callback that fires when file is added */ onAdd?: | ((path: string) => MaybePromise) | undefined /** Callback that fires when file changes */ onChange: (path: string) => MaybePromise /** Callback that fires when watcher is shutdown */ onClose?: (() => MaybePromise) | undefined /** Callback that fires when file is removed */ onRemove?: ((path: string) => MaybePromise) | undefined } export type Plugin = { /** Contracts provided by plugin */ contracts?: (() => MaybePromise) | undefined /** Plugin name */ name: string /** Run plugin logic */ run?: | ((config: { /** All resolved contracts from config and plugins */ contracts: Contract[] /** Whether TypeScript is detected in project */ isTypeScript: boolean /** Previous plugin outputs */ outputs: readonly { plugin: Pick imports?: string prepend?: string content: string }[] }) => MaybePromise<{ imports?: string prepend?: string content: string }>) | undefined /** * Validate plugin configuration or other @wagmi/cli settings require for plugin. */ validate?: (() => MaybePromise) | undefined /** File system watch config */ watch?: Watch | undefined } export type Config = { /** Contracts to use in commands */ contracts?: ContractConfig[] | undefined /** Output file path */ out: string /** Plugins to run */ plugins?: Plugin[] | undefined } export function defineConfig( config: MaybeArray | (() => MaybePromise>), ) { return config } export const defaultConfig = { out: 'src/generated.ts', contracts: [], plugins: [], } satisfies Config