import { TransactionAnalysisIssue } from "../analyzer.mjs"; import "./coins.mjs"; import "./inputs.mjs"; import { AnalyzedCommandArgument, AnalyzedMoveCallCommand } from "./commands.mjs"; import "@mysten/bcs"; //#region src/transaction-analyzer/rules/balance-flows.d.ts interface CoinFlow { coinType: string; amount: bigint; } /** * Per-address signed balance deltas. Negative = value left the address on * net; positive = value arrived on net. * * `sender` is the transaction sender's signed flows (empty if the sender * didn't move any tracked value). `sponsor` is the gas payer's signed flows * when `gasData.owner` differs from `data.sender`, or `null` when the tx * isn't sponsored. */ interface BalanceFlowsResult { byAddress: Record; sender: CoinFlow[]; sponsor: CoinFlow[] | null; } interface BalanceFlowsMoveCallHandlerContext { getTrackedBalance: (ref: AnalyzedCommandArgument) => TrackedBalance | null; /** * Stable string key for a trackable argument — safe to use as a Map * key to correlate state across commands. Returns `null` for Pure / * Unknown / Withdrawal args. */ keyFor: (arg: AnalyzedCommandArgument) => string | null; /** * Stable key for this command's own output at `outputIndex`. Same * encoding as `keyFor` applied to a Result arg pointing at this slot. */ outputKey: (outputIndex: number) => string; /** Register a tracked `Coin` at this command's `outputIndex` result slot. */ trackCoinResult: (outputIndex: number, coinType: string, balance: bigint) => void; /** Register a tracked `Balance` at this command's `outputIndex` result slot. */ trackBalanceResult: (outputIndex: number, coinType: string, balance: bigint) => void; recordFlow: (address: string | null, coinType: string, amount: bigint) => void; addIssue: (issue: TransactionAnalysisIssue) => void; } /** Return `true` to mark the MoveCall handled; `false` to pass through to subsequent handlers and the generic consume loop. */ type BalanceFlowsMoveCallHandler = (command: AnalyzedMoveCallCommand, ctx: BalanceFlowsMoveCallHandlerContext) => boolean; /** * Factory a handler instance. Called once per `analyze()` run so the * returned handler can hold per-PTB state (e.g. tracking intermediate * results by command index) without leaking across runs. */ type BalanceFlowsMoveCallHandlerFactory = () => BalanceFlowsMoveCallHandler; interface BalanceFlowsAnalyzerOptions { /** When true, the gas budget isn't charged against the gas payer's deltas. */ excludeGasBudget?: boolean; /** * Handler factories for MoveCalls outside the built-in 0x2::coin / * 0x2::balance framework. Each factory is invoked per `analyze()` run, * and the resulting handlers are called in order for each MoveCall; * the first handler that returns `true` wins (suppresses later * handlers and the generic consume loop for that command). */ moveCallHandlers?: BalanceFlowsMoveCallHandlerFactory[]; } declare class TrackedBalance { kind: 'coin' | 'balance'; coinType: string; balance: bigint; ownerAddress: string | null; consumed: boolean; constructor(kind: 'coin' | 'balance', coinType: string, balance: bigint, ownerAddress: string | null); consume(): void; withdraw(amount: bigint): void; } //#endregion export { BalanceFlowsAnalyzerOptions, BalanceFlowsMoveCallHandler, BalanceFlowsMoveCallHandlerContext, BalanceFlowsMoveCallHandlerFactory, BalanceFlowsResult, CoinFlow, TrackedBalance }; //# sourceMappingURL=balance-flows.d.mts.map