Skip to main content

PlanStep

Enum PlanStep 

Source
pub enum PlanStep {
Show 18 variants FlashSwap {
Show 14 fields pool_idx: u8, pool_addr: Address, protocol: Prot, zfo: bool, fee: u16, out_currency: Address, out_amount: u128, in_currency: Address, in_amount: u128, recipient_idx: u8, recipient_pool_addr: Option<Address>, recipient_pool_repays: bool, auto_repay: bool, callback: Plan,
}, Erc20Transfer { token_idx: u8, token_addr: Address, recipient_idx: u8, amount: u128, seeds_pool: Option<Address>, repays_flash: Option<Address>, }, V2SwapCalc { pool_idx: u8, pool_addr: Address, zfo: bool, recipient_idx: u8, fee: u16, out_currency: Address, out_amount: u128, recipient_pool_addr: Option<Address>, recipient_repays: bool, }, V2SwapDirect { pool_idx: u8, pool_addr: Address, zfo: bool, out_amount: u128, recipient_idx: u8, out_currency: Address, recipient_pool_addr: Option<Address>, recipient_repays: bool, }, SelfFund { currency: Address, amount: u128, }, V4Unlock { inner: Plan, pool_manager_idx: u8, }, V4Swap { c0_idx: u8, c1_idx: u8, fee: u16, tick_spacing: i16, hooks_idx: u8, zfo: bool, amount: u128, in_currency: Address, in_amount: u128, out_currency: Address, out_amount: u128, }, V4TakeDelta { currency_idx: u8, currency_addr: Address, recipient_idx: u8, seeds_pool: Option<Address>, }, V4SettleAll, V4TakeCompact { currency_idx: u8, currency_addr: Address, recipient_idx: u8, amount: u128, seeds_pool: Option<Address>, repays_flash: Option<Address>, }, V4SettleDelta { currency_idx: u8, currency_addr: Address, }, V4Sync { currency_idx: u8, currency_addr: Address, }, V4Settle { currency_addr: Address, amount: u128, }, NativeTransfer { amount: u128, }, WethWithdraw { weth_idx: u8, weth_addr: Address, amount: u128, }, WethDeposit { weth_idx: u8, weth_addr: Address, amount: u128, }, V4Batch { entries: Vec<V4BatchSwap>, open_weth: bool, }, V4Mint { currency_idx: u8, currency_addr: Address, recipient_idx: u8, amount: u128, },
}
Expand description

A single node of the execution-ordered, callback-nested command Plan. The nesting IS execution order: a FlashSwap’s callback fires when the swap runs (depth-first); a V4Unlock’s inner runs in the unlock callback.

Each leaf carries BOTH the resolved address-table index (for the byte encoder) and the currency/pool address (for the LedgerOp projection) — Checkpoint 1 keeps this minimal; a later refactor may separate address-collection from emission if it clarifies (see BP7KIR body).

Variants§

§

FlashSwap

A V2 or V3 *_SWAP_COMPACT flash — the pool credits out_currency to the executor and is owed in_currency within callback (the bytes the flash’s callback payload carries, fired when the swap runs).

Fields

§pool_idx: u8
§pool_addr: Address
§protocol: Prot
§zfo: bool
§fee: u16
§out_currency: Address
§out_amount: u128
§in_currency: Address
§in_amount: u128
§recipient_idx: u8
§recipient_pool_addr: Option<Address>

The recipient pool’s address when the flash’s OUTPUT directly seeds a pool (e.g. a V3 flash paying the terminal V2 — v4_v3_v2). None for a →SELF output. Bytes encode recipient_idx; this is ledger-only (the output seeds the pool’s pair-handoff instead of crediting the executor).

§recipient_pool_repays: bool

Whether a pool-recipient flash output REPAYS that pool’s flash debt (a V3→V3 repayment — v4_v3_v3) vs seeds it (a V3 flash feeding the terminal V2 — v4_v3_v2).

§auto_repay: bool

Whether the cmd_executor auto-pays in_currency from the executor’s E[] balance at callback-end (V2/V3 *_SWAP_COMPACT with an empty / no-repay callback). When true, the projection emits a trailing flash-repayment Erc20Transfer after the callback (the auto-pay).

§callback: Plan
§

Erc20Transfer

An ERC20_TRANSFER(token→recipient, amount) from the executor. Doubles as flash-repayment and pair-seed by recipient role (DS4OQD finding 5): when the recipient is a V2 pair being pre-funded, seeds_pool carries that pair’s address so the projection also credits the pair-handoff ledger (a following V2SwapCalc consumes it).

Fields

§token_idx: u8
§token_addr: Address
§recipient_idx: u8
§amount: u128
§seeds_pool: Option<Address>
§repays_flash: Option<Address>

When Some(pool), this transfer repays that flash pool (debited min(amount, owed) so explicit + auto-pay compose without over-debiting).

§

V2SwapCalc

A V2_SWAP_CALC(pool, zfo, recipient, fee) — the terminal-V2 pre-fund rule (2PT5HH): swap from whatever the feeder delivered to the pair, never an exact-out V2_SWAP_COMPACT (over-drains 1 wei → UniswapV2: K). Consumes the pair-handoff credit seeded by a prior Erc20Transfer.

Fields

§pool_idx: u8
§pool_addr: Address
§zfo: bool
§recipient_idx: u8
§fee: u16
§out_currency: Address

The swap’s output currency + amount credited to the executor (the profit / downstream repayment source). Option (B): swaps credit their output so the executor ledger fully accounts.

§out_amount: u128
§recipient_pool_addr: Option<Address>

The recipient pool’s address when the calc pays a mid pool (ledger-only — the bytes encode recipient_idx). The projection routes the output: Some(pool) seeds that pool’s pair-handoff (no executor credit); None + recipient = SELF keeps the executor credit; None + recipient = PM pays into the PM. 2-hop families always pass None (SELF recipients) — the byte-identical case.

§recipient_repays: bool

Whether a pool recipient is a V3 flash repayment (saturating flash_debt reduction, SwapRecipient::PoolRepay) vs a V2 pre-fund seed (SwapRecipient::Pool). Together with recipient_pool_addr.

§

V2SwapDirect

An exact-out V2_SWAP_DIRECT(pool, zfo, out_amount, recipient) — the V2 handoff that pays a specific out_amount to recipient (a next pool or the executor). Distinct from PlanStep::V2SwapCalc (exact-in) and PlanStep::FlashSwap (credit-the-executor). Ledger: consumes the donor pool’s seeded H[pool]; the output goes to the recipient — SELF credits the executor, a pool seeds that pool (recipient_pool_addr, ledger-only).

Fields

§pool_idx: u8
§pool_addr: Address
§zfo: bool
§out_amount: u128
§recipient_idx: u8
§out_currency: Address

The exact-out currency (the recipient pool’s input / the executor profit token). Credited to the executor when the recipient is SELF; the seeded-currency for a pool recipient.

§recipient_pool_addr: Option<Address>

The recipient pool’s address when the direct pays a mid pool.

§recipient_repays: bool

Whether a pool recipient is a V3 flash repayment (PoolRepay) vs a V2 pre-fund seed (Pool).

§

SelfFund

A self-fund seed (ADR-029 FundingSource::SelfFund) — the executor holds amount of currency as entry capital before the stream. Not a command; a stream precondition the validator credits so SelfFund families’ flash repayments validate. The encoder emits nothing for it.

Fields

§currency: Address
§amount: u128
§

V4Unlock

A V4_UNLOCK(inner) — the PM callback scope. inner runs inside the unlock; at its end the master V4 invariant fires: every touched PM delta must net to zero (V4UnlockEnd).

Fields

§inner: Plan
§pool_manager_idx: u8
§

V4Swap

A V4_SWAP_COMPACT(c0, c1, fee, ts, hooks, zfo, amount) — creates PM[in] debt and PM[out] credit (both legs modeled so net-zero is checkable).

Fields

§c0_idx: u8
§c1_idx: u8
§fee: u16
§tick_spacing: i16
§hooks_idx: u8
§zfo: bool
§amount: u128
§in_currency: Address
§in_amount: u128
§out_currency: Address
§out_amount: u128
§

V4TakeDelta

V4_TAKE_DELTA(cur→rcp) — takes the entire positive PM[cur] delta to rcp (the profit capture; debits PM credit). When the recipient is a V2 pool (seeds_pool), the taken credit seeds that pool’s pair-handoff (the 2PT5HH terminal-V2 rule across the V4 boundary — v3_v4_v2).

Fields

§currency_idx: u8
§currency_addr: Address
§recipient_idx: u8
§seeds_pool: Option<Address>

When the recipient is a V2 pair, the taken credit seeds it (PM→pool).

§

V4SettleAll

V4_SETTLE_ALL — auto-settle every touched PM currency to 0.

§

V4TakeCompact

V4_TAKE_COMPACT(cur→rcp, amount) — take a specific amount of cur’s PM credit to rcp (the boundary-take: V4 output leaves the PM to feed a V2/V3 hop or to capture profit). Debits PM (D0 credit-before-debit). The recipient role determines the second ledger effect (the cross-ledger move, mirroring Erc20Transfer’s seeds_pool/repays_flash): recipient_idx == SENTINEL_SELF credits the executor Erc20[cur] (the token arrives at the executor); seeds_pool = Some(pool) credits PairHandoff[pool] (the token seeds a V2 pair directly, PM→pool, never touching executor Erc20).

Fields

§currency_idx: u8
§currency_addr: Address
§recipient_idx: u8
§amount: u128
§seeds_pool: Option<Address>

When Some(pool), the take’s recipient is a V2 pair being pre-funded directly (PM→pool) — credit PairHandoff[pool] so a following V2SwapCalc sees its seed. None for a →SELF take.

§repays_flash: Option<Address>

When Some(pool), the take is a flash repayment to that pool (a V3 flash repaid directly from the PM — e.g. the v4_v4_v3 tail). The take debits PM and saturating-repays the pool’s flash debt (no executor Erc20 debit). None for a take/seed.

§

V4SettleDelta

V4_SETTLE_DELTA(cur) — auto-settle one currency’s PM delta to 0.

Fields

§currency_idx: u8
§currency_addr: Address
§

V4Sync

V4_SYNC(cur) — sync the PM’s internal balance for cur (a balance-sync primitive, delta-neutral: it carries no PM-delta effect; the actual delta application comes from a following V4Settle). Used in the boundary-seed pattern (executor pays cur into the PM via an Erc20Transfer(cur→PM) then V4Settle) to settle a V4 input debt.

Fields

§currency_idx: u8
§currency_addr: Address
§

V4Settle

V4_SETTLE — the executor pays amount of currency into the PM, cancelling debt (PM[currency] += amount; the executor’s Erc20 debit happens at the preceding Erc20Transfer(cur→PM)). Used after a V4Sync + Erc20Transfer boundary-seed. The byte form is the no-arg V4_SETTLE; the IR carries currency/amount explicitly so the validator knows which delta to apply.

Fields

§currency_addr: Address
§amount: u128
§

NativeTransfer

NATIVE_TRANSFER(amount) — the executor→PM native pay-in leg of a native settle. Ledger-only (encodes to nothing, like SelfFund): on-chain the native flows as msg.value on the V4_SETTLE* call, so there is no separate byte instruction. Modeled explicitly so the executor’s native debit is a separate observable op (a missing settle half is caught by PM-net-zero, not absorbed).

Fields

§amount: u128
§

WethWithdraw

WETH_WITHDRAW(amount) — unwrap WETH to native (the source of native for a NativeTransfer PM pay-in, or to seed a native V4 input).

Fields

§weth_idx: u8
§weth_addr: Address
§amount: u128
§

WethDeposit

WETH_DEPOSIT(amount) — wrap native to WETH (the native came from a V4TakeCompact(native→SELF)).

Fields

§weth_idx: u8
§weth_addr: Address
§amount: u128
§

V4Batch

V4_BATCH (0x42) / V4_BATCH_OPEN_WETH (0x43) — a bundled PM extcall of up to 8 swaps (encoders::enc_v4_batch / encoders::enc_v4_batch_open_weth). Ledger-equivalent to the constituent V4Swaps: each entry applies the same PM[in] debt / PM[out] credit. Asymmetry vs a plain V4Swap sequence: the 0x42 contract auto-settles any positive native ETH and WETH delta at the batch’s end (an implicit V4_TAKE_DELTA(→SELF) for those two currencies). For the WETH-only slice (the executor’s proven path) the derive therefore omits the terminal V4TakeDelta when use_v4_batch is set — the batch already captured the WETH profit. The Plan mirrors this: the per-entry ledger deltas leave a positive PM[weth] that the trailing V4SettleAll zeroes (the gate’s master invariant fires at V4UnlockEnd — the profit capture is modelled by the contract, not by a Take op here).

open_weth: false = 0x42 (full tail-settle); true = 0x43 — the WETH tail-settle is SKIPPED, so the positive PM[weth] delta is left OPEN for a trailing V4Mint (ERC6909 capture, TGUZCT/SW42JA). The 0x43 projection additionally emits the LedgerOp::OpenWethPairing gate op, which requires a WETH Mint before V4UnlockEnd.

Fields

§entries: Vec<V4BatchSwap>
§open_weth: bool
§

V4Mint

V4_MINT_COMPACT(cur→rcp, amount) — convert a positive PM[cur] delta into an ERC6909 claim for rcp (BP7KIR erc6909_profit opt). Ledger-equivalent to PlanStep::V4TakeDelta: debits PM[cur] by amount (requires credit-before-debit, D0). The asset stays inside the PM as a claim rather than a physical transfer — distinct from V4TakeDelta on-chain, identical for the gate’s safety invariants.

Fields

§currency_idx: u8
§currency_addr: Address
§recipient_idx: u8
§amount: u128

Trait Implementations§

Source§

impl Clone for PlanStep

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PlanStep

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for PlanStep

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PlanStep

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more