import { type Address, type PublicClient, type StateOverride } from "viem"; import type { TransactionPlan } from "../../services/executionService/executionServiceTypes.js"; import type { SlotHints } from "./slotHints.js"; export type DeriveStateOverridesOptions = { /** Override the native (ETH) balance. Defaults to 1000 ETH. Set to 0n to skip. */ nativeBalance?: bigint; /** Permit2 contract address. Required for approval overrides. */ permit2Address: Address; /** * Skip ERC20 balance overrides entirely. Use when the caller has already * validated that the account holds sufficient funds (e.g. UI form validation). * No `balanceOf` reads, no slot probing — only allowance overrides + native * balance + Permit2 deterministic overrides are emitted. */ noBalanceOverride?: boolean; /** * Skip ERC20 allowance overrides entirely (the Permit2 deterministic * overrides are still emitted because they cost no RPC). Use when the * caller knows the account has already approved the relevant spenders. */ noAllowanceOverride?: boolean; /** * Caller-supplied wallet snapshot. Lets the SDK skip per-call `balanceOf` * and `allowance` reads when the supplied values already cover the * requirement. * * - `balances[token]`: when ≥ the plan's required amount, no override * is emitted and no `balanceOf` RPC fires. * - `allowances[token:spender]`: when `maxUint256`, no override is emitted * and no `allowance` RPC fires. */ wallet?: { balances?: Record
; allowances?: Record<`${Address}:${Address}`, bigint>; }; /** * Caller-supplied storage slot hints. When the `balanceSlotIndex` or * `allowanceSlotIndex` is present for a token, the SDK computes the slot * cryptographically and bypasses access-list discovery. Missing entries * fall through to the SDK's own probing + final access-list fallback. * * Pre-fetch with `fetchErc20SlotHints` (exported from this module) to * amortise discovery across many simulate/estimate calls. */ slotHints?: SlotHints; }; /** * Generate all state overrides needed to simulate a TransactionPlan * for an account that may not have sufficient tokens or approvals. * * Combines: * - Native balance override (ETH) * - ERC20 balance overrides (via storage slot discovery) * - ERC20 approval + Permit2 allowance overrides * * @param client - viem PublicClient (must support eth_createAccessList and eth_call with state overrides) * @param plan - TransactionPlan from the SDK's execution service * @param account - the connected wallet address * @param options - Permit2 address and optional native balance override * * @example * ```ts * const plan = sdk.executionService.planDeposit({ ... }) * const permit2 = sdk.deploymentService.getDeployment(chainId).addresses.coreAddrs.permit2 * const overrides = await deriveStateOverrides(client, plan, account, { permit2Address: permit2 }) * // Use overrides with simulateContract or eth_call * ``` */ export declare function deriveStateOverrides(client: PublicClient, plan: TransactionPlan, account: Address, options: DeriveStateOverridesOptions): Promise