import type { Address, Hex } from "viem"; import type { RpcEstimateUserOperationGasReturnType, RpcUserOperation, RpcUserOperationRequest } from "viem/account-abstraction"; import type { DapiPublicError } from "./dapi-errors.js"; import { DalpSdkError } from "./sdk-error.js"; /** * viem's ERC-4337 RPC **input** types, re-exported under SDK-owned names so * consumer code never imports from `viem`. These stay type-only — `import type` * keeps viem's account-abstraction runtime off the published call path. The * viem generic is pinned to `"0.9"` because the DALP bundler serves EntryPoint * v0.9 only and reconstructs a `UserOperation<"0.9">` from the v0.9 fields; the * version-generic types would accept older-EntryPoint fields (`initCode`, * `paymasterAndData`) the server silently drops. */ export type DalpEstimateUserOperationGasReturnType = RpcEstimateUserOperationGasReturnType<"0.9">; export type DalpUserOperation = RpcUserOperation<"0.9">; export type DalpUserOperationRequest = RpcUserOperationRequest<"0.9">; /** * ERC-7769 / ERC-4337 account-abstraction JSON-RPC error codes, vendored from * `kit/dapi/src/routes/bundler/types.ts`. The catalog is non-contiguous: * `-32506` is intentionally absent from this v0.9 dispatcher surface. The codes * are fixed by ERC-7769, so the drift test (`bundler.test.ts`) asserts these * against the explicit standard values as a transcription guard. */ export declare const BUNDLER_AA_ERROR_CODES: { readonly AA_VALIDATION: -32500; readonly AA_PAYMASTER_VALIDATION: -32501; readonly AA_OPCODE: -32502; readonly AA_OUT_OF_TIME_RANGE: -32503; readonly AA_PAYMASTER_THROTTLED: -32504; readonly AA_STAKE: -32505; readonly AA_SIGNATURE: -32507; readonly AA_PAYMASTER_BALANCE: -32508; }; export declare const BUNDLER_VENDOR_ERROR_CODES: { readonly EXECUTION_REVERTED: -32521; }; /** Name of a vendored ERC-7769 account-abstraction error code. */ export type BundlerAaErrorName = keyof typeof BUNDLER_AA_ERROR_CODES; export type BundlerVendorErrorName = keyof typeof BUNDLER_VENDOR_ERROR_CODES; /** Options for constructing a {@link DalpBundlerError}. */ export interface DalpBundlerErrorOptions { /** The numeric JSON-RPC error code returned by the bundler endpoint. */ code: number; message: string; why: string; fix: string; aaErrorName?: BundlerAaErrorName; vendorErrorName?: BundlerVendorErrorName; revertData?: Hex; dapiError?: DapiPublicError; status?: number; /** Whether the failure is retryable. Defaults to `false` when omitted. */ retryable?: boolean; cause?: unknown; } declare class DalpBundlerRpcError extends DalpSdkError { /** The vendored AA error name when `code` maps to a known ERC-7769 code. */ readonly aaErrorName?: BundlerAaErrorName; readonly vendorErrorName?: BundlerVendorErrorName; readonly revertData?: Hex; constructor(options: DalpBundlerErrorOptions); } /** * A bundler/paymaster JSON-RPC failure. Extends {@link DalpSdkError}; the * `code` field carries the numeric ERC-7769 JSON-RPC error code so callers can * branch on `BUNDLER_AA_ERROR_CODES`. The concrete class is re-typed here so * `code` surfaces as `number` rather than ORPCError's inherited `string`. */ export type DalpBundlerError = Omit & { readonly code: number; }; export declare const DalpBundlerError: { new (options: DalpBundlerErrorOptions): DalpBundlerError; readonly prototype: DalpBundlerError; }; /** * A mined or in-flight UserOperation as returned by `eth_getUserOperationByHash`. * * SDK-owned (not viem's `RpcGetUserOperationByHashReturnType`) because the server * emits a DALP-partial shape: a mined result carries only * `userOperation: { sender, nonce }` with `blockHash: null`, while an in-flight * result carries the full canonical UserOperation with `blockNumber`/`blockHash`/ * `transactionHash` null. Fields the server always emits are required; fields it * omits are optional. */ export interface BundlerUserOperationByHash { userOperation: { sender: Address; nonce: Hex; callData?: Hex; callGasLimit?: Hex; verificationGasLimit?: Hex; preVerificationGas?: Hex; maxFeePerGas?: Hex; maxPriorityFeePerGas?: Hex; factory?: Address; factoryData?: Hex; paymaster?: Address; paymasterVerificationGasLimit?: Hex; paymasterPostOpGasLimit?: Hex; paymasterData?: Hex; signature?: Hex; }; entryPoint: Address; transactionHash: Hex | null; blockNumber: Hex | null; blockHash: Hex | null; } /** A single log entry within a {@link BundlerUserOperationReceipt}. */ export interface BundlerUserOperationReceiptLog { address: Address; /** Raw indexed EVM log topics for this UserOperation-attributed event. */ topics: Hex[]; data: Hex; blockNumber: Hex; blockHash: Hex | null; transactionHash: Hex; transactionIndex: Hex; logIndex: Hex; removed: boolean; } /** * A UserOperation receipt as returned by `eth_getUserOperationReceipt`. * * SDK-owned (not viem's `RpcUserOperationReceipt`) because the server emits a * minimal `receipt` ({@link BundlerUserOperationReceipt.receipt}), logs with a * nullable `blockHash`, and a nullable `paymaster`. */ export interface BundlerUserOperationReceipt { userOpHash: Hex; entryPoint: Address; sender: Address; nonce: Hex; paymaster: Address | null; actualGasCost: Hex; actualGasUsed: Hex; success: boolean; logs: BundlerUserOperationReceiptLog[]; receipt: { transactionHash: Hex; blockNumber: Hex; transactionIndex: Hex; }; } /** Result of `pm_getPaymasterStubData`. */ export interface BundlerPaymasterStubData { paymaster: Address; paymasterData: Hex; paymasterVerificationGasLimit?: Hex; paymasterPostOpGasLimit?: Hex; } /** Result of `pm_getPaymasterData`. */ export interface BundlerPaymasterData { paymaster: Address; paymasterData: Hex; } /** * Configuration for {@link createDalpBundlerClient}. * * Unlike {@link createDalpClient}, `apiKey` is **required**: the bundler * endpoint is auth-only (`requireApiKey: true`) with no public variant. */ export interface DalpBundlerClientConfig { /** Base URL of the DALP API (e.g., `"https://dalp.example.com"`). */ url: string; /** API key for the bundler endpoint (issued via the DALP dashboard or CLI). */ apiKey: string; /** * Organization ID for multi-tenant setups. * Pass this explicitly when the API key may map to more than one organization. */ organizationId?: string; /** * Additional headers merged into every request. Cannot override the security * headers (`x-api-key`, `x-organization-id`). */ headers?: Record | (() => Record | Promise>); /** Custom `fetch` implementation (logging, proxy, test doubles). */ fetch?: typeof globalThis.fetch; } /** A typed client over the eight ERC-4337 / ERC-7677 bundler JSON-RPC methods. */ export interface DalpBundlerClient { /** `eth_sendUserOperation` — submit a caller-signed UserOperation; resolves to its hash. */ sendUserOperation(userOperation: RpcUserOperation<"0.9">, entryPoint: Address): Promise; /** * `eth_estimateUserOperationGas` — estimate gas limits for a UserOperation. * Takes the partial request shape (`RpcUserOperationRequest`): the gas and * signature fields the estimate computes need not be populated. */ estimateUserOperationGas(userOperation: RpcUserOperationRequest<"0.9">, entryPoint: Address): Promise>; /** `eth_getUserOperationByHash` — resolves the (DALP-partial) UserOperation, or `null` on miss. */ getUserOperationByHash(hash: Hex): Promise; /** `eth_getUserOperationReceipt` — resolves the receipt, or `null` on miss. */ getUserOperationReceipt(hash: Hex): Promise; /** `eth_supportedEntryPoints` — the EntryPoint addresses this bundler serves. */ getSupportedEntryPoints(): Promise; /** * `eth_chainId` — the served chain id as a `bigint`, decoded from its hex * quantity. Returns `bigint` (not `number`) so chain ids above * `Number.MAX_SAFE_INTEGER` are represented without precision loss. */ getChainId(): Promise; /** * `pm_getPaymasterStubData` — stub paymaster data for gas estimation. Takes * the partial request shape (`RpcUserOperationRequest`); paymaster fields are * what this call produces. */ getPaymasterStubData(userOperation: RpcUserOperationRequest<"0.9">, entryPoint: Address, chainId: number | bigint, context?: unknown): Promise; /** * `pm_getPaymasterData` — final paymaster sponsorship data. Takes the partial * request shape (`RpcUserOperationRequest`). */ getPaymasterData(userOperation: RpcUserOperationRequest<"0.9">, entryPoint: Address, chainId: number | bigint, context?: unknown): Promise; } export declare function createDalpBundlerClient(config: DalpBundlerClientConfig): DalpBundlerClient; export {}; //# sourceMappingURL=bundler.d.ts.map