import {z} from 'zod' export type AddressHash = string; export type FullHash = string; export type GetApiChainIdApiV2ProxyAccountAbstractionOperationsArgs = {sender?: AddressHash | undefined, bundler?: AddressHash | undefined, paymaster?: AddressHash | undefined, factory?: AddressHash | undefined, transaction_hash?: FullHash | undefined, entry_point?: AddressHash | undefined, bundle_index?: number | undefined, block_number?: number | undefined, items_count?: number | undefined, page_size?: number | undefined, page_token?: string | undefined, chain_id: string}; export type GetApiChainIdApiV2ProxyAccountAbstractionOperationsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const addressHash = z.string(); export const implementation = z.object({address_hash: addressHash, name: z.string().nullable()}); export const metadataTag = z.object({meta: z.record(z.string(), z.unknown()).nullable(), name: z.string(), ordinal: z.number().int(), slug: z.string(), tagType: z.enum(["name", "generic", "classifier", "information", "note", "protocol"])}); export const metadata = z.object({tags: z.array(metadataTag)}); export const tag = z.object({address_hash: addressHash, display_name: z.string(), label: z.string()}); export const proxyType = z.enum(["eip1167", "eip1967", "eip1822", "eip1967_oz", "eip1967_beacon", "master_copy", "basic_implementation", "basic_get_implementation", "comptroller", "eip2535", "clone_with_immutable_arguments", "eip7702", "resolved_delegate_proxy", "erc7760", "minimal_proxy"]).nullable(); export const watchlistName = z.object({display_name: z.string(), label: z.string()}); export const address = z.object({ens_domain_name: z.string().nullable(), hash: addressHash, implementations: z.array(implementation), is_contract: z.boolean().nullable(), is_scam: z.boolean(), is_verified: z.boolean().nullable(), metadata: metadata.nullable(), name: z.string().nullable(), private_tags: z.array(tag).optional(), proxy_type: proxyType, public_tags: z.array(tag).optional(), reputation: z.enum(["ok", "scam"]), watchlist_names: z.array(watchlistName).optional()}); export const integerString = z.string(); export const fullHash = z.string(); export const timestampNullable = z.string().nullable(); export const userOperationInList = z.object({address: address, block_number: integerString, entry_point: address, entry_point_version: z.enum(["v0.6", "v0.7", "v0.8", "v0.9"]), fee: integerString, hash: fullHash, status: z.boolean(), timestamp: timestampNullable, transaction_hash: fullHash}); export const getApiChainIdApiV2ProxyAccountAbstractionOperationsResponse = z.object({items: z.array(userOperationInList), next_page_params: z.record(z.string(), z.unknown()).nullable()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List of recent user operations * * GET /{chain_id}/api/v2/proxy/account-abstraction/operations * * Also accepts auth: apiKeyAuth */ export const getApiChainIdApiV2ProxyAccountAbstractionOperations = async (args: GetApiChainIdApiV2ProxyAccountAbstractionOperationsArgs, options?: GetApiChainIdApiV2ProxyAccountAbstractionOperationsOptions) => { const {baseUrl = "https://api.blockscout.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.sender != null) query.append("sender", String(args.sender)) if (args.bundler != null) query.append("bundler", String(args.bundler)) if (args.paymaster != null) query.append("paymaster", String(args.paymaster)) if (args.factory != null) query.append("factory", String(args.factory)) if (args.transaction_hash != null) query.append("transaction_hash", String(args.transaction_hash)) if (args.entry_point != null) query.append("entry_point", String(args.entry_point)) if (args.bundle_index != null) query.append("bundle_index", String(args.bundle_index)) if (args.block_number != null) query.append("block_number", String(args.block_number)) if (args.items_count != null) query.append("items_count", String(args.items_count)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page_token != null) query.append("page_token", String(args.page_token)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.chain_id))}/api/v2/proxy/account-abstraction/operations${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiChainIdApiV2ProxyAccountAbstractionOperationsResponse, await res.json()) };