Skip to main content

Module replacement

Module replacement 

Source
Expand description

Notifications from replacementSubscribe: one reroute result per original swap. Nothing stands in for the original; the original kind is the original itself.

Each notification is a ReplacementNotification, tagged by kind:

Every kind flattens ReplacementCore and L1Score into its top level; the kinds that simulate a whole transaction also flatten SimCost.

Wire keys are the camelCase of the field names (batch_index is batchIndex), except ReplacementCore::error, which is err. Units:

  • Token amounts are raw base units of their mint, with no decimals applied.
  • fee is in lamports.
  • Changes are in basis points (bps): 1 bps = 0.01%.
  • swapMode is ExactIn or ExactOut.
  • blockTime is a Unix timestamp in seconds.

Structs§

ChangeBps
A recorded change, and whether CHANGE_CLAMP_BPS is what bounded it.
L1Score
What the original swap filled, and how the stand-in scored against it. Flattened into the notification’s top level. l1 in a name means the original (onchain) swap.
OriginalNotification
The original swap replayed as the baseline (kind: "original"): the historical transaction re-run against the state it was quoted at, so the other kinds can be scored against a number produced the same way rather than against the chain’s.
ProbedHop
The hop a venue probe re-priced, as the original swap ran it onchain and as the replay ran it.
ReplacementContext
The slot the payload was produced at, in the shape every other subscription’s context takes.
ReplacementCore
The identity and outcome every notification carries, whatever its kind. Flattened into the notification’s top level.
RequoteNotification
A transaction rerouted through the router (kind: "requote"): the original swap’s transaction re-quoted and simulated. The original still executed onchain; this result is never committed.
RerouteLegNotification
One swap of a transaction rerouted through the router.
Signature
A 64-byte Ed25519 signature.
SimCost
What simulating the stand-in cost. Flattened into the notification’s top level.
VenueNotification
A venue probe (kind: "directFill"): one hop rerouted directly to a venue through your template, simulated against the state it would have traded on.

Enums§

ReplacementNotification
One reroute result for an original swap, streamed over replacementSubscribe: through the router, directly to a venue, or the original swap replayed as the baseline. Nothing stands in for the original. Tagged by kind, with the variant’s fields at the top level beside it.

Constants§

BPS_SCALE
Basis points per whole unit.
CHANGE_CLAMP_BPS
The bound on one swap’s recorded change: ±100,000 bps (±1,000%). Losses stop at −10,000 bps (−100%) on their own, so only gains reach it.

Functions§

clamped_change_bps
Change from base to new in bps, (new - base) * 10_000 / base, clamped to ±CHANGE_CLAMP_BPS.