fix: a V4 step of chained swap actions shows what the user receives (closes #563)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run

A V4 step's input side is now the currency its SETTLE or SETTLE_ALL
names, and its output side the one its TAKE or TAKE_ALL names. A side
none of them names comes from the swap actions, lined up as the
exact-out ones in reverse order and then the exact-in ones in order,
since the router runs exact-out actions from the output end: the input
from the first, the output from the last. Amount is the first action's
amountIn and Min. received the last one's minimum, each shown only when
that action spends the input currency or buys the output currency.
SETTLE_ALL and TAKE_ALL were not read before, and the first swap action
set both sides.

Model: opus-5-5
This commit is contained in:
2026-10-18 20:21:16 +00:00
parent f00954e2c5
commit 8d524b7f3d
3 changed files with 473 additions and 144 deletions
+32 -13
View File
@@ -1164,8 +1164,9 @@ read:
amount of one step that names an input token or amount: the last
`PERMIT2_PERMIT` step if there is one, otherwise the first V2 or V3 exact-in,
V2 exact-out, `WRAP_ETH` or V4 swap step. A V2 exact-out step gives its
`amountInMax`, and a V4 swap step the `amountIn` of its first readable
exact-in action.
`amountInMax`, and a V4 swap step the `amountIn` of the first of its swap
actions as they are lined up below, or none when that action is exact-out,
could not be read or does not spend the step's input currency.
- `Whatever an earlier step sent to the pair (V2 already paid)`: the swap's
`Amount` line, when the amount it shows is a V2 exact-in `amountIn` of zero.
The router reads that zero as "the pair already holds the input tokens": the
@@ -1186,17 +1187,35 @@ read:
The swap's `Token In` and `Token Out` lines name a currency, not an amount; each
reads `Unknown (not named in the calldata)` when the decoder found no token for
that side, or `Unknown (could not be decoded)` instead when a V4 swap action in
the transaction could not be read (see Transaction Decoding below). A V4 step
whose swap action could not be read still sets each side as a swap step does,
and a side its `SETTLE` or `TAKE` did not name is then unknown: no other step's
token or figure is shown for it. An `UNWRAP_WETH` step makes `Token Out` ETH
only when the output side is WETH, on mainnet or Sepolia, or when no step set
the output side; a WETH `Min. received` figure then reads in ETH. Otherwise
`Token Out` and `Min. received` keep the output side's own token and figure,
whether the swap was paid in ETH or in a token: a V2 exact-out swap that buys
USDC and then unwraps the WETH it did not spend shows USDC. The token permission
warning on the signature screen has its own amount wording, including `Unknown`;
the SignApproval section below describes it.
the transaction could not be read (see Transaction Decoding below). A V4 step's
input side is the currency its `SETTLE` or `SETTLE_ALL` names, and its output
side the currency its `TAKE` or `TAKE_ALL` names. A side none of them names
comes from the step's swap actions, lined up as the exact-out actions in reverse
order, then the exact-in actions in the order they appear: the input side from
the first action in that line, the output side from the last. The router runs
exact-in actions from the input end and a chain of exact-out actions from the
output end, so a step whose swap actions are all of one kind is lined up from
what the user pays to what the user receives. A step that mixes the two kinds
need not be: one that buys WETH with USDT exact-in and then USDC with that WETH
exact-out is lined up with the USDC purchase first. `Amount` is the first
action's `amountIn`, shown only when that action spends the step's input
currency, and `Min. received` the last action's `amountOutMin`, shown only when
that action buys the step's output currency, so no figure is shown against a
currency it is not counted in. The decoder reads no amount from an exact-out
action. That mixed step, ending in `SETTLE_ALL` USDT and `TAKE_ALL` USDC, reads
`Swap USDT → USDC` with neither figure, since its first action in the line is
exact-out and its last buys WETH. A swap action that could not be read keeps its
place in the line and states nothing, so a side or figure that would come from
it is unknown, while one from a readable action is shown. Such a step still sets
each side as a swap step does, and no other step's token or figure is shown for
an unknown one. An `UNWRAP_WETH` step makes `Token Out` ETH only when the output
side is WETH, on mainnet or Sepolia, or when no step set the output side; a WETH
`Min. received` figure then reads in ETH. Otherwise `Token Out` and
`Min. received` keep the output side's own token and figure, whether the swap
was paid in ETH or in a token: a V2 exact-out swap that buys USDC and then
unwraps the WETH it did not spend shows USDC. The token permission warning on
the signature screen has its own amount wording, including `Unknown`; the
SignApproval section below describes it.
The swap's `Deadline` line is the router's deadline as a UTC date and time, e.g.
`2026-02-27 08:25:51`. A JavaScript date reaches only to 275760-09-13 00:00:00