import type { HexString } from '../types/index.js'; /** State-changing call. */ export declare const CALL: 1; /** Read-only call. */ export declare const STATICCALL: 2; /** ETH-value call — ETH amount is taken from the first input specifier's state slot. */ export declare const VALUECALL: 3; /** Raw calldata mode — set in the flags byte to bypass ABI encoding. */ export declare const FLAG_RAW: 32; /** Extended command mode — the next command word contains up to 32 input specifiers. */ export declare const FLAG_EXTENDED_COMMAND: 64; /** Sentinel value for unused input slots or a discarded return value. */ export declare const UNUSED_SLOT: 255; /** Maximum number of state slots (stateBitmap is uint128). */ export declare const MAX_STATE_SLOTS = 128; export type WeirollCallType = typeof CALL | typeof STATICCALL | typeof VALUECALL; export type WeirollTarget = HexString | { type: 'magic'; key: string; }; /** A single step in a weiroll script. */ export interface WeirollAction { /** 20-byte target contract address. */ target: WeirollTarget; /** 4-byte function selector (e.g. `0x12345678`). */ selector: HexString; callType: WeirollCallType; /** * Weiroll input specifiers for the call's inputs. * Fixed-length arguments use the state slot index directly. * Variable-length arguments set the high bit and store the state slot index in * the low 7 bits. */ inputs: number[]; /** Weiroll output specifier, or UNUSED_SLOT to discard. */ output: number; /** When true, sets FLAG_RAW — use for manually ABI-encoded calldata. */ rawMode?: boolean; } /** * Describes the initial value of a single state slot. * * - `literal` — fixed ABI-encoded value, pinned at whitelist time * - `magic` — resolved from PoolContext by key * - `configurable` — resolved from configurableValues by key * - `runtime` — placeholder filled at execution time (not pinned) */ export type WorkflowStateSlot = { type: 'literal'; value: HexString; } | { type: 'magic'; key: string; } | { type: 'configurable'; key: string; label?: string; parameter?: string; actionName?: string; actionIndex?: number; inputIndex?: number; anonymous?: boolean; system?: 'payableValue'; } | { type: 'rawcalldata'; selector: HexString; parameterTypes: string[]; sourceSlots: number[]; actionName?: string; actionIndex?: number; } | { type: 'template'; workflow: WorkflowDefinition; label?: string; actionName?: string; actionIndex?: number; inputIndex?: number; } | { type: 'runtime'; key: string; label?: string; parameter?: string; actionName?: string; actionIndex?: number; inputIndex?: number; anonymous?: boolean; system?: 'payableValue'; }; /** The full description of a workflow: its actions and initial state layout. */ export interface WorkflowDefinition { /** Stable identifier for the workflow (matches the catalog ref). */ workflowRef: string; actions: WeirollAction[]; state: WorkflowStateSlot[]; /** * Named runtime variables required at execution time. Copied from * MarketplaceWorkflow. One input per entry; the value is written into every * state slot whose key matches, enforcing a single value across multiple uses. */ runtimeVariables?: string[]; } /** * Protocol-level values available for magic variable resolution. * All values must already be ABI-encoded (e.g. uint256 as a 32-byte hex). */ export type PoolContext = Record; export interface ScriptResult { /** ABI-encoded bytes32 command words, one per action. */ commands: HexString[]; /** ABI-encoded state slot values. Runtime slots are initialized to empty bytes. */ state: HexString[]; /** * uint128 where bit i = 1 means state[i] is pinned (known at whitelist time). * Bit i = 0 means runtime — the executor fills the slot at call time. */ stateBitmap: bigint; } /** * Fills runtime state slots with execution-time values. * * `buildScript()` initializes runtime slots to empty bytes. Before calling * `OnchainPM.execute()`, the strategist must fill each runtime slot with the * concrete value for this particular execution. * * Returns a copy of `state` with each runtime slot replaced by the * corresponding value from `runtimeValues` (keyed by the slot's `key` field). * * @throws if any required runtime variable in `workflow.runtimeVariables` has no * corresponding entry in `runtimeValues` * * @example * ```typescript * const { commands, state, stateBitmap } = buildScript(workflow, { poolContext, configurableValues }) * const filledState = fillRuntimeSlots(state, workflow, { amount: '0x000...0de0b6b3a7640000' }) * // submit OnchainPM.execute(commands, filledState, stateBitmap, [], proof) * ``` */ export declare function fillRuntimeSlots(state: HexString[], workflow: WorkflowDefinition, runtimeValues: Record): HexString[]; /** * Packs a single weiroll command into a 32-byte word. * * Bit layout (from MSB): * ``` * bits [255:224] selector (bytes4) — function selector * bits [223:216] flags (uint8) — callType | FLAG_RAW * bits [215:168] inputs (bytes6) — 6 × 1-byte input specifiers, MSB first * bits [167:160] output (uint8) — output specifier or UNUSED_SLOT * bits [159:0] target (address) — 20-byte contract address * ``` * * Equivalent Solidity expression: * ```solidity * (uint256(uint32(selector)) << 224) | (flags << 216) | (indices << 168) | (output << 160) | uint160(target) * ``` */ export declare function encodeCommand(selector: HexString, // 4 bytes flags: number, // 1 byte: callType | optional FLAG_RAW inputs: number[], // up to 6 weiroll input specifiers (padded to 6 with UNUSED_SLOT) output: number, // output specifier or UNUSED_SLOT target: HexString): HexString; /** * Builds the weiroll commands array and initial state from a workflow * definition, resolving magic variables and configurable values. * * State slots classified as `literal`, `magic`, or `configurable` are pinned: * their bit in `stateBitmap` is set to 1 and the resolved value is placed in * `state[i]`. Slots classified as `runtime` are initialized to empty bytes * with their bit set to 0 — the executor fills them at call time. * * @throws if a magic variable key is absent from `poolContext` * @throws if a configurable key is absent from `configurableValues` * @throws if the workflow has more than 128 state slots */ export declare function buildScript(workflow: WorkflowDefinition, context: { poolContext: PoolContext; configurableValues: Record; }): ScriptResult; //# sourceMappingURL=weiroll.d.ts.map