import * as P from 'micro-packed'; import { type IWeb3Provider } from '../utils.ts'; type Writable = T extends {} ? { -readonly [P in keyof T]: Writable; } : T; type ArrLike = Array | ReadonlyArray; export type IsEmptyArray = T extends ReadonlyArray ? (T['length'] extends 0 ? true : false) : true; export type Component = { readonly name?: string; readonly type: T; }; export type NamedComponent = Component & { readonly name: string; }; export type BaseComponent = Component; export type Tuple>> = { readonly name?: string; readonly type: 'tuple'; readonly components: TC; }; type IntIdxType = '' | '8' | '16' | '24' | '32' | '40' | '48' | '56' | '64' | '72' | '80' | '88' | '96' | '104' | '112' | '120' | '128' | '136' | '144' | '152' | '160' | '168' | '176' | '184' | '192' | '200' | '208' | '216' | '224' | '232' | '240' | '248' | '256'; type UintType = `uint${IntIdxType}`; type IntType = `int${IntIdxType}`; type NumberType = UintType | IntType; type ByteIdxType = '' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '28' | '29' | '30' | '31' | '32'; type ByteType = `bytes${ByteIdxType}`; export type MapTuple = T extends ArrLike & { name: string; }> ? { [K in T[number] as K['name']]: MapType; } : T extends ArrLike> ? { [K in keyof T]: T[K] extends BaseComponent ? MapType : unknown; } : unknown; export type GetType = T extends `${infer Base}[]${infer Rest}` ? GetType<`${Base}${Rest}`>[] : T extends `${infer Base}[${number}]${infer Rest}` ? GetType<`${Base}${Rest}`>[] : T extends 'address' ? string : T extends 'string' ? string : T extends 'bool' ? boolean : T extends NumberType ? bigint : T extends ByteType ? Uint8Array : unknown; export type MapType = T extends Tuple>> ? MapTuple : T extends Component ? GetType : unknown; export type UnmapType = T extends MapType ? U : never; export declare function mapComponent(c: T): P.CoderType>>; export type ArgsType | undefined> = IsEmptyArray extends true ? undefined : T extends ReadonlyArray ? T['length'] extends 1 ? MapType : MapTuple : MapTuple; export declare function mapArgs>>(args: T): P.CoderType>>; export type FunctionType = Component<'function'> & { readonly inputs?: ReadonlyArray>; readonly outputs?: ReadonlyArray>; }; type ContractMethodDecode> = IsEmptyArray extends true ? { decodeOutput: (b: Uint8Array) => void; } : { decodeOutput: (b: Uint8Array) => O; }; type ContractMethodEncode> = IsEmptyArray extends true ? { encodeInput: () => Uint8Array; } : { encodeInput: (v: I) => Uint8Array; }; type ContractMethodGas> = IsEmptyArray extends true ? { estimateGas: () => Promise; } : { estimateGas: (v: I) => Promise; }; type ContractMethodCall, O = ArgsType> = IsEmptyArray extends true ? IsEmptyArray extends true ? { call: () => Promise; } : { call: () => Promise; } : IsEmptyArray extends true ? { call: (v: I) => Promise; } : { call: (v: I) => Promise; }; export type ContractMethod = ContractMethodEncode & ContractMethodDecode; export type ContractMethodNet = ContractMethod & ContractMethodGas & ContractMethodCall; export type FnArg = { readonly type: string; readonly name?: string; readonly components?: ArrLike; readonly inputs?: ArrLike; readonly outputs?: ArrLike; readonly anonymous?: boolean; readonly indexed?: boolean; }; export type ContractTypeFilter = { [K in keyof T]: T[K] extends FunctionType & { name: string; } ? T[K] : never; }; export type ContractType, N, F = ContractTypeFilter> = F extends ArrLike ? { [K in F[number] as K['name']]: N extends IWeb3Provider ? ContractMethodNet : ContractMethod; } : never; export declare function evSigHash(o: FnArg): string; export declare function fnSigHash(o: FnArg): string; export declare function createContract>(abi: T, net: IWeb3Provider, contract?: string): ContractType, IWeb3Provider>; export declare function createContract>(abi: T, net?: undefined, contract?: string): ContractType, undefined>; type GetCons> = Extract; type ConstructorType = Component<'constructor'> & { readonly inputs?: ReadonlyArray>; }; type ConsArgs = IsEmptyArray extends true ? undefined : ArgsType; export declare function deployContract>(abi: T, bytecodeHex: string, ...args: GetCons extends never ? [args: unknown] : ConsArgs> extends undefined ? [] : [args: ConsArgs>]): string; export type EventType = NamedComponent<'event'> & { readonly inputs: ReadonlyArray>; }; export type ContractEventTypeFilter = { [K in keyof T]: T[K] extends EventType ? T[K] : never; }; export type TopicsValue = { [K in keyof T]: T[K] | null; }; export type EventMethod = { decode: (topics: string[], data: string) => ArgsType; topics: (values: TopicsValue>) => (string | null)[]; }; export type ContractEventType, F = ContractEventTypeFilter> = F extends ArrLike ? { [K in F[number] as K['name']]: EventMethod; } : never; export declare function events>(abi: T): ContractEventType>; export type ContractABI = ReadonlyArray; export type ContractInfo = { abi: 'ERC20' | 'ERC721' | 'ERC1155' | ContractABI; symbol?: string; decimals?: number; name?: string; price?: number; }; export type HintOpt = { contract?: string; amount?: bigint; contractInfo?: ContractInfo; contracts?: Record; }; export type HintFn = (value: unknown, opt: HintOpt) => string; export type HookFn = (decoder: Decoder, contract: string, info: SignatureInfo, opt: HintOpt) => SignatureInfo; type SignaturePacker = { name: string; signature: string; packer: P.CoderType; hint?: HintFn; hook?: HookFn; }; type EventSignatureDecoder = { name: string; signature: string; decoder: (topics: string[], _data: string) => unknown; hint?: HintFn; }; export type SignatureInfo = { name: string; signature: string; value: unknown; hint?: string; }; export declare class Decoder { contracts: Record>; sighashes: Record; evContracts: Record>; evSighashes: Record; add(contract: string, abi: ContractABI): void; method(contract: string, data: Uint8Array): string | undefined; decode(contract: string, _data: Uint8Array, opt: HintOpt): SignatureInfo | SignatureInfo[] | undefined; decodeEvent(contract: string, topics: string[], data: string, opt: HintOpt): SignatureInfo | SignatureInfo[] | undefined; } export {}; //# sourceMappingURL=decoder.d.ts.map