/** * Reconstructs RAILGUN transactions from the V2 event log stream alone. * * Before the `Action` event, a transaction's nullifiers, commitments and bound params * could only be recovered by decoding `transact()` calldata out of a call trace, which * needs `debug_trace*` from the RPC. No engine RPC path has that, which is why the V2 TXID * merkletree has only ever been buildable from the subgraph. `Action` carries the * per-transaction shape directly, so the same records can be built from logs: * * event Action(address caller, TXConfig[] txconfigs); * struct TXConfig { * uint32 nullifiersCount; * uint32 commitmentsCount; // EXCLUDES the unshield commitment * bool hasUnshield; * bytes32 boundParamsHash; * } * * Log order within one `transact()` call-frame, guaranteed by RailgunSmartWallet.sol and * asserted by its own tests (`Nullified` is events[0], `Action` is events[1]): * * [ Nullified x N, Action, (Unshield | nested frame)*, Transact? ] * * `shield()` emits `Action(caller, [])` as its first log - an empty txconfigs array marks * a shield frame, which produces no transaction records. * * `Transact` is emitted only `if (commitments.length > 0)`, so a frame whose transactions * are all unshield-only emits none and therefore has no output tree position. * * A called contract may re-enter RAILGUN, nesting a whole frame inside the parent's * post-`Action` window. A child always completes before the parent resumes, so the * innermost open frame is always the correct owner of the next `Unshield` / `Transact`. * * This module speaks only plain values - no ethers types, no database types - so it can be * exercised directly from hand-written log fixtures. Decoding lives in V2-events.ts and * assembly of the engine's RailgunTransactionV2 lives in its caller. */ import { TokenData } from '../../../models/formatted-types'; export type ActionTxConfig = { nullifiersCount: number; /** Commitments this transaction contributes to the Transact event; excludes the unshield. */ commitmentsCount: number; hasUnshield: boolean; boundParamsHash: string; }; export type ActionUnshieldRecord = { to: string; token: TokenData; /** Post-fee amount, as emitted. The unshield preimage value is `amount + fee`. */ amount: bigint; fee: bigint; }; export type RailgunActionLog = { kind: 'action'; logIndex: number; caller: string; txconfigs: readonly ActionTxConfig[]; } | { kind: 'nullified'; logIndex: number; treeNumber: number; nullifiers: readonly string[]; } | ({ kind: 'unshield'; logIndex: number; } & ActionUnshieldRecord) | { kind: 'transact'; logIndex: number; treeNumber: number; startPosition: number; hashes: readonly string[]; }; export type DerivedActionTransaction = { /** Index of the transact() call-frame within the EVM transaction, in execution order. */ frameOrdinal: number; /** * Record number within the EVM transaction, continuing across call-frames. This is the * order the subgraph assigns ids in, so records agree across the cutover. */ recordIndex: number; caller: string; nullifiers: readonly string[]; utxoTreeIn: number; boundParamsHash: string; hasUnshield: boolean; /** * Accumulated commitments only. The unshield commitment is NOT emitted by any event and * must be appended by the caller - see resolveUnshieldCommitment in V2-events.ts. */ commitments: readonly string[]; /** Undefined when the frame emitted no Transact event (every transaction unshield-only). */ utxoTreeOut: number | undefined; utxoBatchStartPositionOut: number | undefined; unshield: ActionUnshieldRecord | undefined; }; /** * Derive every RAILGUN transaction in one EVM transaction from its RAILGUN logs. * * `logs` must be that EVM transaction's logs emitted by the RAILGUN proxy, in log-index * order, already decoded. Logs from any other contract must be filtered out first. */ export declare const deriveTransactionsFromActionLogs: (logs: readonly RailgunActionLog[]) => DerivedActionTransaction[];