---
# System prepended metadata

title: 'dex: augment SwapExecution tra'

---

### dex: augment `SwapExecution` traces with position data


**Context**
In Penumbra, `SwapExecution` record an execution trace of swap input transformed into swap output ($\Delta \rightarrow \Lambda$).

```rust 
pub struct SwapExecution {
    pub traces: Vec<Vec<Value>>,
    /// The input value that was consumed.
    pub input: Value,
    /// The output value that was produced.
    pub output: Value,
}
```

The swap execution contains a list of traces, where each trace contains an ordered list of values, which correspond to a hop in the graph. So, for example, if we swap between USDC and UM, and we obtain a trace as follow:

- 50 USDC
- 20 OSMO
- 10 UM

This can be parsed as "a trade that started with 50 USDC, which turned into 20 OSMO, which then were converted into 10 UM".

It is useful because it means that we can decompose a trade into the set of routes that it takes, and decompose each route into the set of hops that it contains.

**Augmenting `SwapExecution`**
It would be useful if in addition to the value at each hop, the stack of traces contained a `position::Id` corresponding to the position that was executed against at that hop.

**Plan**

We want to extend the `SwapExecution` data structure to track positions at each hop:

```rust
pub struct SwapExecution {
    pub traces: Vec<Vec<Value>>,
    pub traces_lps: Vec<Vec<position::Id>>,
    pub input: Value,
    pub output: Value,
}
```

To do that we need to:
1. Track positions that receive execution at each hop
2. Surface those positions in the `FrontierCache`
3. And we need to make sure that we don't introduce cache incoherency bugs
4. This should not be consensus breaking




